From a9ffd3351da3bc94e52784b34fd1daa3a3e8078d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 19 Apr 2018 08:40:04 -0400 Subject: [PATCH] [welcome] Support sr@latin - The QLocale constructor which takes a string (locale name) doesn't understand sr@latin, and returns the Cyrillic locale. Fix that by creating locales ourselves for @latin locales. - sr and sr@latin now display correctly in the right script in the native language dropdown. --- src/modules/welcome/WelcomePage.cpp | 36 +++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index 48f5e5f1c..95569318d 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -135,28 +135,29 @@ bool matchLocale( QComboBox& list, QLocale& matchFound, std::function 2 ) + if ( locale.contains( '_' ) && QLocale::countriesForLanguage( m_locale.language() ).count() > 2 ) { sortKey.append( QString( " (%1)" ) - .arg( QLocale::countryToString( thisLocale.country() ) ) ); + .arg( QLocale::countryToString( m_locale.country() ) ) ); // If the language name is RTL, make this parenthetical addition RTL as well. QString countryFormat = label.isRightToLeft() ? QString( QChar( 0x202B ) ) : QString(); countryFormat.append( QLatin1String( " (%1)" ) ); - label.append( countryFormat.arg( thisLocale.nativeCountryName() ) ); + label.append( countryFormat.arg( m_locale.nativeCountryName() ) ); } m_sortKey = sortKey; m_label = label; } - QString m_locale; // the locale identifier, e.g. "en_GB" + QLocale m_locale; + QString m_localeId; // the locale identifier, e.g. "en_GB" QString m_sortKey; // the English name of the locale QString m_label; // the native name of the locale @@ -180,7 +181,18 @@ struct LocaleLabel */ constexpr bool isEnglish() const { - return m_locale == QLatin1Literal( "en_US" ) || m_locale == QLatin1Literal( "en" ); + return m_localeId == QLatin1Literal( "en_US" ) || m_localeId == QLatin1Literal( "en" ); + } + + static QLocale getLocale( const QString& localeName ) + { + if ( localeName.contains( "@latin" ) ) + { + QLocale loc( localeName ); + return QLocale( loc.language(), QLocale::Script::LatinScript, loc.country() ); + } + else + return QLocale( localeName ); } } ; @@ -203,8 +215,8 @@ WelcomePage::initLanguages() for ( const auto& locale : localeList ) { - cDebug() << locale.m_locale << locale.m_sortKey; - ui->languageWidget->addItem( locale.m_label, QLocale( locale.m_locale ) ); + cDebug() << locale.m_localeId << locale.m_sortKey; + ui->languageWidget->addItem( locale.m_label, locale.m_locale ); } } @@ -253,7 +265,7 @@ WelcomePage::initLanguages() [&]( int newIndex ) { QLocale selectedLocale = ui->languageWidget->itemData( newIndex, Qt::UserRole ).toLocale(); - cDebug() << "Selected locale" << selectedLocale.name(); + cDebug() << "Selected locale" << selectedLocale; QLocale::setDefault( selectedLocale ); CalamaresUtils::installTranslator( selectedLocale,