From 19797d40350d07afea2e706e45ec44a6fdf05250 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 16 Aug 2013 21:33:22 +0200 Subject: [PATCH] fix handling of country-less languages like esperanto it's impossible to instantiate QLocale objects like that, so the language setting would be simply clobbered. instead, we now convert between numerical and string codes directly. unfortunately QLocale has no public api for that. but we are including private QTranslator headers already anyway, so whatever. Task-number: QTBUG-14592 Change-Id: I95189c1898aa1fb5520ecf7057521597ed9331f1 Reviewed-by: hjk Reviewed-by: Oswald Buddenhagen --- src/linguist/shared/translator.cpp | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/linguist/shared/translator.cpp b/src/linguist/shared/translator.cpp index f5f4ab7..37929f3 100644 --- a/src/linguist/shared/translator.cpp +++ b/src/linguist/shared/translator.cpp @@ -62,6 +62,7 @@ #include #include +#include #include QT_BEGIN_NAMESPACE @@ -367,30 +368,19 @@ bool Translator::save(const QString &filename, ConversionData &cd, const QString QString Translator::makeLanguageCode(QLocale::Language language, QLocale::Country country) { - QLocale locale(language, country); - if (country == QLocale::AnyCountry) { - QString languageCode = locale.name().section(QLatin1Char('_'), 0, 0); - if (languageCode.length() <= 3) - return languageCode; - return QString(); - } else { - return locale.name(); + QString result = QLocalePrivate::languageToCode(language); + if (language != QLocale::C && country != QLocale::AnyCountry) { + result.append(QLatin1Char('_')); + result.append(QLocalePrivate::countryToCode(country)); } + return result; } void Translator::languageAndCountry(const QString &languageCode, QLocale::Language *lang, QLocale::Country *country) { - QLocale locale(languageCode); - if (lang) - *lang = locale.language(); - - if (country) { - if (languageCode.indexOf(QLatin1Char('_')) != -1) - *country = locale.country(); - else - *country = QLocale::AnyCountry; - } + QLocale::Script script; + QLocalePrivate::getLangAndCountry(languageCode, *lang, script, *country); } int Translator::find(const TranslatorMessage &msg) const -- 2.7.4