summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qlocale_unix.cpp13
-rw-r--r--tests/auto/corelib/tools/qlocale/tst_qlocale.cpp2
2 files changed, 14 insertions, 1 deletions
diff --git a/src/corelib/tools/qlocale_unix.cpp b/src/corelib/tools/qlocale_unix.cpp
index 3602319f67..d46ced463c 100644
--- a/src/corelib/tools/qlocale_unix.cpp
+++ b/src/corelib/tools/qlocale_unix.cpp
@@ -117,6 +117,19 @@ QLocale QSystemLocale::fallbackLocale() const
lang = qgetenv("LC_MESSAGES");
if (lang.isEmpty())
lang = qgetenv("LANG");
+ // if the locale is the "C" locale, then we can return the language we found here:
+ if (lang.isEmpty() || lang == QByteArray("C") || lang == QByteArray("POSIX"))
+ return QLocale(QString::fromLatin1(lang));
+
+ // if the locale is not the "C" locale and LANGUAGE is not empty, return
+ // the first part of LANGUAGE if LANGUAGE is set and has a first part:
+ QByteArray language = qgetenv("LANGUAGE");
+ if (!language.isEmpty()) {
+ language = language.split(':').first();
+ if (!language.isEmpty())
+ return QLocale(QString::fromLatin1(language));
+ }
+
return QLocale(QString::fromLatin1(lang));
}
diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
index 7e12e42107..ddfa23eefb 100644
--- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
@@ -437,7 +437,7 @@ void tst_QLocale::emptyCtor()
// Get an environment free of any locale-related variables
QStringList env;
foreach (QString const& entry, QProcess::systemEnvironment()) {
- if (entry.startsWith("LANG=") || entry.startsWith("LC_"))
+ if (entry.startsWith("LANG=") || entry.startsWith("LC_") || entry.startsWith("LANGUAGE="))
continue;
env << entry;
}