diff options
author | Mike FABIAN <maiku.fabian@gmail.com> | 2012-06-04 17:53:34 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-06-06 15:29:34 +0200 |
commit | 897e19f95ee91ec21bb9dd9f3157ee7333c9018f (patch) | |
tree | 66f35a8c87bc698c17562ab2beba4a22e1bb775e | |
parent | 7dfee3ffc5129307217eb949698c5088a4561642 (diff) |
Check LANGUAGE as well in QSystemLocale::fallbackLocale
Because QSystemLocale::fallbackLocale() is about UI languages,
it makes sense to check LANGUAGE as well if appropriate.
Adapt tst_qlocale.cpp accordingly.
Suggested by Oswald Buddenhagen.
Change-Id: Ib2c9674081809e3251be4e34456b05210eebc010
Reviewed-by: Oswald Buddenhagen
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
-rw-r--r-- | src/corelib/tools/qlocale_unix.cpp | 13 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qlocale/tst_qlocale.cpp | 2 |
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; } |