Details
-
Bug
-
Resolution: Incomplete
-
Not Evaluated
-
None
-
5.6.0, 5.6.1, 5.7.0
-
None
-
OSX El Capitan
Description
QTranslator is behaving wrongly on my system.
My system regional settings are configured like this:
- Preferred languages: English, French, German
- Region: France - French
- Formatting language: French
Qt is correctly discovering my locale
QLocale(French, Latin, France) ("en", "fr", "de", "zh-Hans", "zh-Hant", "ja", "es", "it", "nl", "ko", "pt-BR", "pt-PT", "da", "fi", "nb", "sv", "ru", "pl", "tr", "ar", "th", "cs", "hu", "ca", "hr", "el", "he", "ro", "sk", "uk", "id", "ms", "vi")
Though QTranslator taking a QLocale ctor parameter fallback loading is not working fine.
Qt is natively english and do not propose 'en' qm files.
Because of that every Qt application open in French (or any of the matching preferred language appearing in QLocale::uiLanguages()).
English in this case is a never reachable language for my configuration.
Probably QCoreApplication is missing a property which could help the fallback mechanism, something like: QCoreApplication::nativeLanguage() which the application author must set (defaulting to the system local language to keep compatibility).
This property will describe the language used in the source code tr() stuff, and the fallback mechanism could know that English is available and not load French or next preferred language translations.
Test case:
#include <QCoreApplication> #include <QTranslator> #include <QLibraryInfo> #include <QDir> #include <QDebug> void load(const QLocale &locale, const QString &name, const QString& path) { auto translator = new QTranslator(qApp); if (translator->load(locale, name, "_", path)) { qApp->installTranslator(translator); qWarning("%s ok", qPrintable(name)); } else { delete translator; qWarning("%s fails", qPrintable(name)); } } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); //a.setProperty("nativeLanguage", "en"); const QString qmPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath); const QLocale locale; qWarning() << locale << locale.uiLanguages(); qWarning() << qmPath; load(locale, "qtbase", qmPath); load(locale, "qt_help", qmPath); load(locale, "gammaray", "/Volumes/Shared/Development/Builds/QtAuto/GammaRay-Desktop_Qt_5_6_1_clang_64bit-Release/translations"); qWarning() << "QAbstractSocket::Connection refused: " << QCoreApplication::translate("QAbstractSocket", "Connection refused"); qWarning() << "QHelpSearchQueryWidget::Search: " << QCoreApplication::translate("QHelpSearchQueryWidget", "Search"); qWarning() << "GammaRay::AboutPluginsDialog::Failed Plugins: " << QCoreApplication::translate("GammaRay::AboutPluginsDialog", "Failed Plugins"); //qWarning() << "qm:" << QDir(qmPath).entryList({ "qtbase*.qm", "qt_help*.qm" }); return 0; }
Attachments
Issue Links
- relates to
-
QTBUG-31031 QTranslator::load returns false for empty translation-files
- Closed