PDA

View Full Version : Gui partially translated



jiveaxe
2nd May 2014, 18:34
Hi, I have a very strange problem: my application's gui is partially translated although I translated all strings with Qt Linguist. I'm using the following code to load the qm file.


QTranslator appTranslator;
QTranslator qtTranslator;
QStringList uiLanguages;
// uiLanguages crashes on Windows with 4.8.0 release builds
#if (QT_VERSION >= 0x040801) || (QT_VERSION >= 0x040800 && !defined(Q_OS_WIN))
uiLanguages = QLocale::system().uiLanguages();
#else
uiLanguages << QLocale::system().name();
#endif

const QString &appTrPath = QCoreApplication::applicationDirPath()
+ QLatin1String(SHARE_PATH "/translations");

foreach (QString locale, uiLanguages) {
#if (QT_VERSION >= 0x050000)
locale = QLocale(locale).name();
#else
locale.replace(QLatin1Char('-'), QLatin1Char('_')); // work around QTBUG-25973
#endif
if (appTranslator.load(QLatin1String("myapp_") + locale, appTrPath)) {
installTranslator(&appTranslator);

const QString &qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsP ath);
const QString &qtTrFile = QLatin1String("qt_") + locale;
// Binary installer puts Qt tr files into creatorTrPath
if (qtTranslator.load(qtTrFile, qtTrPath) || qtTranslator.load(qtTrFile, appTrPath)) {
installTranslator(&qtTranslator);
setProperty("qtc_locale", locale);
}
break;
} else if (locale == QLatin1String("C") /* overrideLanguage == "English" */) {
// use built-in
break;
} else if (locale.startsWith(QLatin1String("en")) /* "English" is built-in */) {
// use built-in
break;
}
}

Since some strings are correctly translated I presume that the qm file is loaded. I tryed to remove it and, as expected, no string is translated. I loaded the qm file in a binary editor to check reference to untranslated text and the missing strings are there.

to create the qm files I follow the usual procedure:

lupdate -no-obsolete *.cpp *.ui *.h -ts ../translations/*.ts
(translation with Qt Linguist)
cd ../translations
lrelease *.ts

Any idea how debug the problem?

Thanks

jiveaxe
3rd May 2014, 14:20
Solved. Untranslated strings come from static classes. Using "construct on first use" idiom fixed the issue.