How to enter a static methods for Qt Linguist QTranslator

佐手、 提交于 2019-12-08 10:50:27

问题


I have a Qt Linguist *.ts file like:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="de_DE" sourcelanguage="en_GB">
<context>
    <name></name>
    <message>
        <location filename="classWithStaticMethod.cpp" line="60"/>
        <source>File</source>
        <translation>Datei</translation>
    </message>
</context>
</TS>

How do I enter a translation object with a static method.

ClassWithStaticMethod.cpp has a static method where a QT_TR_NOOP("File")

occurs at line 60 for instance. Leaving the name tags empty does nott work.


回答1:


Static variables are instantiated (and thus, constructor code run) before your int main function is run. The translation code is set up in the QApplication constructor (I believe), which isn't run until your int main function has been entered. Thus, you are trying to get the translation of a string before the code to support it has been initialized.

To avoid this, you could either accept that the given string isn't translated and explicitly translate it every time it is used, or use the Construct on First Use idiom instead of a static member variable.



来源:https://stackoverflow.com/questions/33482054/how-to-enter-a-static-methods-for-qt-linguist-qtranslator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!