我目前正在翻译我们的 Qt gui。
我有以下代码:
// header file
static const QString Foo;
// cpp file
const QString FooConstants::Foo = "foo";
// another cpp file
editMenu->addAction(tr(FooConstants::Foo));
虽然这似乎不起作用。
也就是说,.ts 文件中没有上述常量的条目。
如果我这样做,它就会起作用:
// another cpp file
editMenu->addAction(tr("foo"));
但是,这个常量用在很多地方,我不想手动更新每个字符串文字。 (如果以后要改变的话)
有人能帮忙吗?
最佳答案
将文字包装在 QT_TR_NOOP
中宏观:
// cpp file
const QString FooConstants::Foo = QT_TR_NOOP("foo");
来自guide :
If you need to have translatable text completely outside a function, there are two macros to help: QT_TR_NOOP() and QT_TRANSLATE_NOOP(). They merely mark the text for extraction by the lupdate tool. The macros expand to just the text (without the context).
关于c++ - Qt tr 似乎不适用于静态常量成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1486492/