summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlocale_unix.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-05-24 16:27:08 +0200
committerLiang Qi <liang.qi@qt.io>2018-05-24 16:29:14 +0200
commitf82e5085169876e0ec7c1b744d021b068c281cfe (patch)
treea870e1f68ce62818a0793c4c78a67971e841e676 /src/corelib/tools/qlocale_unix.cpp
parentf74d4fb1dacc682e2e6f4a44e4240f642a2c3b70 (diff)
parentee47999333dde1d38b73d04e142e05f06f8c56ed (diff)
Merge remote-tracking branch 'origin/5.11' into dev
Conflicts: mkspecs/features/qt_common.prf src/corelib/tools/qstring.cpp src/plugins/platforms/windows/qwindowsmousehandler.cpp src/widgets/widgets/qmainwindowlayout_p.h Change-Id: I5df613008f6336f69b257d08e49a133d033a9d65
Diffstat (limited to 'src/corelib/tools/qlocale_unix.cpp')
-rw-r--r--src/corelib/tools/qlocale_unix.cpp34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/corelib/tools/qlocale_unix.cpp b/src/corelib/tools/qlocale_unix.cpp
index 095001e0a3..1a9184bca9 100644
--- a/src/corelib/tools/qlocale_unix.cpp
+++ b/src/corelib/tools/qlocale_unix.cpp
@@ -107,8 +107,36 @@ Q_GLOBAL_STATIC(QSystemLocaleData, qSystemLocaleData)
#ifndef QT_NO_SYSTEMLOCALE
+static bool contradicts(const QByteArray &maybe, const QByteArray &known)
+{
+ if (maybe.isEmpty())
+ return false;
+
+ /*
+ If \a known (our current best shot at deciding which language to use)
+ provides more information (e.g. script, country) than \a maybe (a
+ candidate to replace \a known) and \a maybe agrees with \a known in what
+ it does provide, we keep \a known; this happens when \a maybe comes from
+ LANGUAGE (usually a simple language code) and LANG includes script and/or
+ country. A textual comparison won't do because, for example, bn (Bengali)
+ isn't a prefix of ben_IN, but the latter is a refinement of the former.
+ (Meanwhile, bn is a prefix of bnt, Bantu; and a prefix of ben is be,
+ Belarusian. There are many more such prefixings between two- and
+ three-letter codes.)
+ */
+ QLocale::Language langm, langk;
+ QLocale::Script scriptm, scriptk;
+ QLocale::Country landm, landk;
+ QLocalePrivate::getLangAndCountry(maybe, langm, scriptm, landm);
+ QLocalePrivate::getLangAndCountry(known, langk, scriptk, landk);
+ return (langm != QLocale::AnyLanguage && langm != langk)
+ || (scriptm != QLocale::AnyScript && scriptm != scriptk)
+ || (landm != QLocale::AnyCountry && landm != landk);
+}
+
QLocale QSystemLocale::fallbackUiLocale() const
{
+ // See man 7 locale for precedence - LC_ALL beats LC_MESSAGES beats LANG:
QByteArray lang = qgetenv("LC_ALL");
if (lang.isEmpty())
lang = qgetenv("LC_MESSAGES");
@@ -118,12 +146,12 @@ QLocale QSystemLocale::fallbackUiLocale() const
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:
+ // ... otherwise, if the first part of LANGUAGE says more than or
+ // contradicts what we have, use that:
QByteArray language = qgetenv("LANGUAGE");
if (!language.isEmpty()) {
language = language.split(':').constFirst();
- if (!language.isEmpty())
+ if (contradicts(language, lang))
return QLocale(QString::fromLatin1(language));
}