QT_TR_NOOP: translation files are generated, but translated strings never used, why?
In an application I have a lot of classes that are apparently not descendants of QObject, and these objects apparently throw exceptions, and those exceptions apparently need to be translated. So, I enclosed every string thrown in exception in QT_TR_NOOP macro. That allowed me to generate translation files. But when I run my program, strings are still not translated. If I try to get them via QApplication::translate ("MyClassName", "Text in english"), I can get strings fine, but QT_TR_NOOP ("Text in english") returns just text in english. Are there any extra steps I should take to make it work right?
Also, a little side question: if开发者_Python百科 I'm using QT_TR_NOOP in a function that is not a member of any class, what will happen? Does Qt just silently ignore this situation?
It seems that I got the whole thing wrong :(
QT_TR_NOOP is for marking strings for translation outside functions; it is supposed to return original text. What I needed was to apply translations to the non-qt classes, which is described in detail here:
Internationalization with Qt: Translating Non-Qt Classes
Sorry for bothering.
QT_TR_NOOP only marks the text as something that may need translation (so that it shows up in Qt Linguist) but it doesn't do any translating. For that you need to use tr().
精彩评论