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>
This commit is contained in:
Mike FABIAN 2012-06-04 17:53:34 +02:00 committed by Qt by Nokia
parent 7dfee3ffc5
commit 897e19f95e
2 changed files with 14 additions and 1 deletions

View File

@ -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));
}

View File

@ -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;
}