summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2012-05-02 14:23:34 +0200
committerQt by Nokia <qt-info@nokia.com>2012-05-04 12:52:30 +0200
commitf7b1262c7f34e9c685f30dbf7a31ff62e7736795 (patch)
tree72a6eae6f7dc3f5bae11951b0eaad18b9880e20f /src
parent500f4883b4ff93841f520bd61260eb3d11563b88 (diff)
Always return uiLanguages in bcp47 format
The old code didn't convert the uilanguages coming from the system locale to bcp47 format, leading to QLocale().uiLanguages() and QLocale("en_US").uiLanguages() returning things in an inconsistent format. Now it always returns bcp47 format (ie. Language and Country separated by a hyphen). Change-Id: I40d3442255e6e8daa4723f7b3fc13829c9764eb1 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com> Reviewed-by: Denis Dzyubenko <denis.dzyubenko@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qlocale_unix.cpp38
1 files changed, 18 insertions, 20 deletions
diff --git a/src/corelib/tools/qlocale_unix.cpp b/src/corelib/tools/qlocale_unix.cpp
index 5f7a9da95d..b4a560b718 100644
--- a/src/corelib/tools/qlocale_unix.cpp
+++ b/src/corelib/tools/qlocale_unix.cpp
@@ -71,6 +71,7 @@ struct QSystemLocaleData
QLocale lc_messages;
QByteArray lc_messages_var;
QByteArray lc_measurement_var;
+ QStringList uiLanguages;
};
void QSystemLocaleData::readEnvironment()
@@ -212,29 +213,26 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const
return QVariant((int)QLocale(meas_locale).measurementSystem());
}
case UILanguages: {
- static QString languages = QString::fromLatin1(qgetenv("LANGUAGE"));
- if (!languages.isEmpty()) {
- QStringList lst = languages.split(QLatin1Char(':'));
- for (int i = 0; i < lst.size();) {
- const QString &name = lst.at(i);
- QString lang, script, cntry;
- if (name.isEmpty() || !qt_splitLocaleName(name, lang, script, cntry))
- lst.removeAt(i);
- else
- ++i;
- }
- return lst;
- }
- if (!d->lc_messages_var.isEmpty()) {
+ if (!d->uiLanguages.isEmpty())
+ return d->uiLanguages;
+ QString languages = QString::fromLatin1(qgetenv("LANGUAGE"));
+ QStringList lst;
+ if (languages.isEmpty())
+ lst.append(QString::fromLatin1(d->lc_messages_var));
+ else
+ lst = languages.split(QLatin1Char(':'));
+
+ for (int i = 0; i < lst.size(); ++i) {
+ const QString &name = lst.at(i);
QString lang, script, cntry;
- if (qt_splitLocaleName(QString::fromLatin1(d->lc_messages_var.constData(), d->lc_messages_var.size()),
- lang, script, cntry)) {
- if (!cntry.length() && lang.length())
- return QStringList(lang);
- return QStringList(lang % QLatin1Char('-') % cntry);
+ if (qt_splitLocaleName(name, lang, script, cntry)) {
+ if (!cntry.length())
+ d->uiLanguages.append(lang);
+ else
+ d->uiLanguages.append(lang % QLatin1Char('-') % cntry);
}
}
- return QVariant();
+ return d->uiLanguages.isEmpty() ? QVariant() : QVariant(d->uiLanguages);
}
case StringToStandardQuotation:
return lc_messages.quoteString(in.value<QStringRef>());