[libcalamaresui] Cleanup locale-labeling code
- Support translations of the "language (country)" format instead of forcing English parenthesis.
This commit is contained in:
parent
084f4d2445
commit
1f4ac45bb5
@ -270,26 +270,27 @@ LocaleLabel::LocaleLabel( const QString& locale )
|
|||||||
: m_locale( LocaleLabel::getLocale( locale ) )
|
: m_locale( LocaleLabel::getLocale( locale ) )
|
||||||
, m_localeId( locale )
|
, m_localeId( locale )
|
||||||
{
|
{
|
||||||
|
QString longFormat = tr( "%1 (%2)", "Language (Country)" );
|
||||||
|
|
||||||
QString sortKey = QLocale::languageToString( m_locale.language() );
|
QString sortKey = QLocale::languageToString( m_locale.language() );
|
||||||
QString label = m_locale.nativeLanguageName();
|
QString languageName = m_locale.nativeLanguageName();
|
||||||
|
QString countryName;
|
||||||
|
|
||||||
if ( label.isEmpty() )
|
if ( languageName.isEmpty() )
|
||||||
label = QString( QLatin1Literal( "* %1 (%2)" ) ).arg( locale, sortKey );
|
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() ) ) );
|
countryName = m_locale.nativeCountryName();
|
||||||
|
|
||||||
// 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() ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_sortKey = sortKey;
|
m_sortKey = sortKey;
|
||||||
m_label = label;
|
m_label = needsCountryName ? longFormat.arg( languageName ).arg( countryName ) : languageName;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLocale LocaleLabel::getLocale( const QString& localeName )
|
QLocale LocaleLabel::getLocale( const QString& localeName )
|
||||||
|
Loading…
Reference in New Issue
Block a user