From 897e19f95ee91ec21bb9dd9f3157ee7333c9018f Mon Sep 17 00:00:00 2001 From: Mike FABIAN Date: Mon, 4 Jun 2012 17:53:34 +0200 Subject: 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 --- src/corelib/tools/qlocale_unix.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/corelib/tools/qlocale_unix.cpp') 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)); } -- cgit v1.2.3