QTranslator and installTranslator
i have in my project qml file with qsTr() function. i create also a translation files for this qml. in the main program i create a QDeclarativeView object to run th开发者_如何学运维e qml file, and also a QTranslator. i send a pointer to this Qtranslator, and pointer to the QApplication to another function that is called when the language was changed. at this function i write:
QLocale myLocale;
QString locale = myLocale.name();
m_translator->load(pagePrefix +'_'+ locale);//(QLibraryInfo::TranslationsPath));
m_appManager->installTranslator(m_translator);
and then i loaded the qml file again. but this didn't change the translation(and the locale was changed). i don't know where the problem is....
verify in your code that the translator is loaded successfuly.
bool loaded = false;
loaded = m_translator->load(pagePrefix +'_'+ locale);
if (!loaded)
qWarning() << QString("can't load %1 translation").arg(locale);
with this you can see if your file is correctly lodad or not at all. if not verify the path of your .qm file. If yes make sure your .qm have the right translate inside.
and by the way make sure you're installing your translation
m_appManager->installTranslator(m_translator);
before you create your widgets (if I remember correctly you should do it in this order)
精彩评论