From 1f4ac45bb5d6ad4712109bd126a33cf306d35e9d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 14 Dec 2018 11:22:47 +0100 Subject: [PATCH] [libcalamaresui] Cleanup locale-labeling code - Support translations of the "language (country)" format instead of forcing English parenthesis. --- .../utils/CalamaresUtilsGui.cpp | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp index 41465ca02..5e4b8e069 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp @@ -270,26 +270,27 @@ LocaleLabel::LocaleLabel( const QString& locale ) : m_locale( LocaleLabel::getLocale( locale ) ) , m_localeId( locale ) { + QString longFormat = tr( "%1 (%2)", "Language (Country)" ); + QString sortKey = QLocale::languageToString( m_locale.language() ); - QString label = m_locale.nativeLanguageName(); + QString languageName = m_locale.nativeLanguageName(); + QString countryName; - if ( label.isEmpty() ) - label = QString( QLatin1Literal( "* %1 (%2)" ) ).arg( locale, sortKey ); + if ( languageName.isEmpty() ) + languageName = QString( QLatin1Literal( "* %1 (%2)" ) ).arg( locale, sortKey ); - if ( locale.contains( '_' ) && QLocale::countriesForLanguage( m_locale.language() ).count() > 2 ) + bool needsCountryName = locale.contains( '_' ) && QLocale::countriesForLanguage( m_locale.language() ).count() > 2; + + if ( needsCountryName ) { - QLatin1Literal countrySuffix( " (%1)" ); + sortKey.append( '+' ); + sortKey.append( QLocale::countryToString( m_locale.country() ) ); - sortKey.append( QString( countrySuffix ).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( countrySuffix ); - label.append( countryFormat.arg( m_locale.nativeCountryName() ) ); + countryName = m_locale.nativeCountryName(); } m_sortKey = sortKey; - m_label = label; + m_label = needsCountryName ? longFormat.arg( languageName ).arg( countryName ) : languageName; } QLocale LocaleLabel::getLocale( const QString& localeName )