c++ - Qt tr 似乎不适用于静态常量成员?

标签 c++ qt translation

我目前正在翻译我们的 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/

相关文章:

java - 我的语言翻译在谷歌浏览器和 IE 中不起作用

c++ - 提升精神QI : Auto-rule deduction on a tuple with a sequence inside an alternative function

c++ - 元编程,阶乘,C++,boost

c++ - 在 C++ 运行时获取当前操作系统

c++ - 将多个 QTimers 调用排队到插槽

PHP-ZendFramework : How to use Zend_Translate without the whole framework?

c++ - 双向迭代器

c++ - basic_string<CharT> 与 CharT*

linux - 将现有的 OpenCV 应用程序包含到 Qt GUI 中

php - 在模板的 Symfony 翻译中使用 Twig 变量