path: root/src/corelib/kernel
diff options
authorGiuseppe D'Angelo <>2022-07-29 11:38:56 +0200
committerGiuseppe D'Angelo <>2022-08-10 23:21:55 +0200
commitb779b8062cdeef5f2ac33c9164b5846780cfd495 (patch)
tree0e3c9cb5790a5aa1fcc7a84ea0f052bd5bf5088b /src/corelib/kernel
parentc4fabe37b9a97a189b02de4e72d040009892ad08 (diff)
QTranslator: generalize a UNIX-only path
QTranslator builds a list of "candidate" names in order to find out the translation file to load. Part of the name comes from the UI languages, as determined by the QLocale object passed to load() (via QLocale::uiLanguages()). On UNIX this list of languages is processed by adding a lowercase version of each language. In other words, if the list is something like: {"en-Latn-US", "en-US", "en"} then it is changed to contain: {"en-Latn-US", "en-latn-us", "en-US", "en-us", "en"} (The last element is not needlessly duplicated, since it's already fully lowercase.) I am not sure why this is done only on UNIX: the commit introducing this behavior predates public history. If I have to take a guess, it's done because the language is then used to assemble a file name that QTranslator tries to open. On UNIX file names are case sensitive, so if the translation file is called "translations_en_us.qm" it would fail to load under a "en-US" locale (the "-" -> "_" processing is done later). But what about Windows? In principle, turning the names in lowercase is not necessary as Windows' filesystem is case insensitive; a translation file called "translations_en_us.qm" will still be loaded if opened as "translations_en_US.qm"... ... *except* if the file is in the resource system! In that case, filesystem access is still case sensitive, and will fail to load the translation file (which instead would load just fine on UNIX). Plug this silly cross-platform difference by also lowercasing on Windows. Change-Id: I2573721e33d9da08f60a5bb56e35e4553cbe4efe Pick-to: 5.15 6.2 6.3 6.4 Reviewed-by: Oswald Buddenhagen <> Reviewed-by: Edward Welbourne <> Reviewed-by: Kai Koehne <>
Diffstat (limited to 'src/corelib/kernel')
1 files changed, 7 insertions, 2 deletions
diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp
index 1824153966..f6f7ec12d1 100644
--- a/src/corelib/kernel/qtranslator.cpp
+++ b/src/corelib/kernel/qtranslator.cpp
@@ -620,15 +620,20 @@ static QString find_translation(const QLocale & locale,
// see for inspiration
+ // For each language_country returned by locale.uiLanguages(), add
+ // also a lowercase version to the list. Since these languages are
+ // used to create file names, this is important on case-sensitive
+ // file systems, where otherwise a file called something like
+ // "prefix_en_us.qm" won't be found under the "en_US" locale. Note
+ // that the Qt resource system is always case-sensitive, even on
+ // Windows (in other words: this codepath is *not* UNIX-only).
QStringList languages = locale.uiLanguages();
-#if defined(Q_OS_UNIX)
for (int i = languages.size()-1; i >= 0; --i) {
QString lang =;
QString lowerLang = lang.toLower();
if (lang != lowerLang)
languages.insert(i + 1, lowerLang);
for (QString localeName : qAsConst(languages)) {
localeName.replace(u'-', u'_');