From 311af6de5d9a4d157ec6d888e6b85b0aaf9441a1 Mon Sep 17 00:00:00 2001 From: Harald Sitter Date: Thu, 5 Apr 2018 11:57:23 +0200 Subject: [PATCH] [locale] prefer native language and country names when available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This basically means we talk about localization in the respective localized variant. e.g. "German (Germany)" ➡ "Deutsch (Deutschland)". If geoip lookup failed or isn't configured for whatever reason it's a stretch to expect the user to know english enough to find their own language. Preferring the localized strings resolves this issue. Additionally this happens to bypass #712 respectively https://bugreports.qt.io/browse/QTBUG-34287 as the native names are properly spelled. So, as long as Qt has localized names the names will also be properly spelled. --- src/modules/keyboard/KeyboardPage.cpp | 2 ++ src/modules/locale/LocalePage.cpp | 9 +++++++-- src/modules/welcome/WelcomePage.cpp | 1 - 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/modules/keyboard/KeyboardPage.cpp b/src/modules/keyboard/KeyboardPage.cpp index 6f4473014..9056ba273 100644 --- a/src/modules/keyboard/KeyboardPage.cpp +++ b/src/modules/keyboard/KeyboardPage.cpp @@ -369,6 +369,8 @@ KeyboardPage::onActivate() { const auto langParts = lang.split( '_', QString::SkipEmptyParts ); + // Note that this his string is not fit for display purposes! + // It doesn't come from QLocale::nativeCountryName. QString country = QLocale::countryToString( QLocale( lang ).country() ); cDebug() << " .. extracted country" << country << "::" << langParts; diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index 9aad283c6..50f2d9889 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -477,8 +477,13 @@ LocalePage::prettyLCLocale( const QString& lcLocale ) const QLocale locale( localeString ); //: Language (Country) - return tr( "%1 (%2)" ).arg( QLocale::languageToString( locale.language() ) ) - .arg( QLocale::countryToString( locale.country() ) ); + const QString lang = !locale.nativeLanguageName().isEmpty() ? + locale.nativeLanguageName() : + QLocale::languageToString( locale.language() ); + const QString country = !locale.nativeCountryName().isEmpty() ? + locale.nativeCountryName() : + QLocale::countryToString( locale.country() ); + return tr( "%1 (%2)" ).arg( lang ).arg( country ); } void diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index 0a1d2fb7d..4fc44e0d5 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -345,4 +345,3 @@ WelcomePage::focusInEvent( QFocusEvent* e ) ui->languageWidget->setFocus(); e->accept(); } -