[welcome] Present languages in native format
- Introduce intermediate data class for building up the list of languages to present. - Sort on the English names, with en_US at the top (ugh). - Show the native names.
This commit is contained in:
parent
6930400b67
commit
59537d86d6
@ -132,39 +132,85 @@ bool matchLocale( QComboBox& list, QLocale& matchFound, std::function<bool(const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct LocaleLabel
|
||||||
|
{
|
||||||
|
LocaleLabel( const QString& locale )
|
||||||
|
: m_locale( locale )
|
||||||
|
{
|
||||||
|
QLocale thisLocale( locale );
|
||||||
|
QString sortKey = QLocale::languageToString( thisLocale.language() );
|
||||||
|
QString label = thisLocale.nativeLanguageName();
|
||||||
|
|
||||||
|
if ( QLocale::countriesForLanguage( thisLocale.language() ).count() > 2 )
|
||||||
|
{
|
||||||
|
sortKey.append( QString( " (%1)" )
|
||||||
|
.arg( QLocale::countryToString( thisLocale.country() ) ) );
|
||||||
|
label.append( QString( " (%1)" ).arg( thisLocale.nativeCountryName() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
m_sortKey = sortKey;
|
||||||
|
m_label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString m_locale; // 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
|
||||||
|
|
||||||
|
/** @brief Define a sorting order.
|
||||||
|
*
|
||||||
|
* English (@see isEnglish() -- it means en_US) is sorted at the top.
|
||||||
|
*/
|
||||||
|
bool operator <(const LocaleLabel& other) const
|
||||||
|
{
|
||||||
|
if ( isEnglish() )
|
||||||
|
return !other.isEnglish();
|
||||||
|
if ( other.isEnglish() )
|
||||||
|
return false;
|
||||||
|
return m_sortKey < other.m_sortKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief Is this locale English?
|
||||||
|
*
|
||||||
|
* en_US and en (American English) is defined as English. The Queen's
|
||||||
|
* English -- proper English -- is relegated to non-English status.
|
||||||
|
*/
|
||||||
|
constexpr bool isEnglish() const
|
||||||
|
{
|
||||||
|
return m_locale == QLatin1Literal( "en_US" ) || m_locale == QLatin1Literal( "en" );
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
|
||||||
void
|
void
|
||||||
WelcomePage::initLanguages()
|
WelcomePage::initLanguages()
|
||||||
{
|
{
|
||||||
ui->languageWidget->setInsertPolicy( QComboBox::InsertAlphabetically );
|
|
||||||
|
|
||||||
QLocale defaultLocale = QLocale( QLocale::system().name() );
|
|
||||||
|
|
||||||
// Fill the list of translations
|
// Fill the list of translations
|
||||||
|
ui->languageWidget->clear();
|
||||||
|
ui->languageWidget->setInsertPolicy( QComboBox::InsertAtBottom );
|
||||||
|
|
||||||
{
|
{
|
||||||
|
std::list< LocaleLabel > localeList;
|
||||||
const auto locales = QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';');
|
const auto locales = QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';');
|
||||||
for ( const QString& locale : locales )
|
for ( const QString& locale : locales )
|
||||||
{
|
{
|
||||||
QLocale thisLocale = QLocale( locale );
|
localeList.emplace_back( locale );
|
||||||
QString lang = QLocale::languageToString( thisLocale.language() );
|
}
|
||||||
|
|
||||||
cDebug() << "LOCALE" << locale << "lang" << lang << "country" << QLocale::countryToString( thisLocale.country() );
|
localeList.sort(); // According to the sortkey, which is english
|
||||||
cDebug() << " .. countries=" << thisLocale.language() << QLocale::countriesForLanguage( thisLocale.language() );
|
|
||||||
cDebug() << " .. " << thisLocale.nativeLanguageName() << thisLocale.nativeCountryName();
|
|
||||||
|
|
||||||
if ( QLocale::countriesForLanguage( thisLocale.language() ).count() > 2 )
|
for ( const auto& locale : localeList )
|
||||||
lang.append( QString( " (%1)" )
|
{
|
||||||
.arg( QLocale::countryToString( thisLocale.country() ) ) );
|
cDebug() << locale.m_locale << locale.m_sortKey;
|
||||||
|
ui->languageWidget->addItem( locale.m_label, QLocale( locale.m_locale ) );
|
||||||
ui->languageWidget->addItem( lang, thisLocale );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the best initial translation
|
// Find the best initial translation
|
||||||
QLocale selectedLocale;
|
QLocale defaultLocale = QLocale( QLocale::system().name() );
|
||||||
|
QLocale matchedLocale;
|
||||||
|
|
||||||
cDebug() << "Matching exact locale" << defaultLocale;
|
cDebug() << "Matching exact locale" << defaultLocale;
|
||||||
bool isTranslationAvailable =
|
bool isTranslationAvailable =
|
||||||
matchLocale( *(ui->languageWidget), selectedLocale,
|
matchLocale( *(ui->languageWidget), matchedLocale,
|
||||||
[&](const QLocale& x){ return x.language() == defaultLocale.language() && x.country() == defaultLocale.country(); } );
|
[&](const QLocale& x){ return x.language() == defaultLocale.language() && x.country() == defaultLocale.country(); } );
|
||||||
|
|
||||||
if ( !isTranslationAvailable )
|
if ( !isTranslationAvailable )
|
||||||
@ -172,7 +218,7 @@ WelcomePage::initLanguages()
|
|||||||
cDebug() << "Matching approximate locale" << defaultLocale.language();
|
cDebug() << "Matching approximate locale" << defaultLocale.language();
|
||||||
|
|
||||||
isTranslationAvailable =
|
isTranslationAvailable =
|
||||||
matchLocale( *(ui->languageWidget), selectedLocale,
|
matchLocale( *(ui->languageWidget), matchedLocale,
|
||||||
[&](const QLocale& x){ return x.language() == defaultLocale.language(); } ) ;
|
[&](const QLocale& x){ return x.language() == defaultLocale.language(); } ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,16 +228,16 @@ WelcomePage::initLanguages()
|
|||||||
|
|
||||||
cDebug() << "Matching English (US)";
|
cDebug() << "Matching English (US)";
|
||||||
isTranslationAvailable =
|
isTranslationAvailable =
|
||||||
matchLocale( *(ui->languageWidget), selectedLocale,
|
matchLocale( *(ui->languageWidget), matchedLocale,
|
||||||
[&](const QLocale& x){ return x == en_us; } );
|
[&](const QLocale& x){ return x == en_us; } );
|
||||||
|
|
||||||
// Now, if it matched, because we didn't match the system locale, switch to the one found
|
// Now, if it matched, because we didn't match the system locale, switch to the one found
|
||||||
if ( isTranslationAvailable )
|
if ( isTranslationAvailable )
|
||||||
QLocale::setDefault( selectedLocale );
|
QLocale::setDefault( matchedLocale );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isTranslationAvailable )
|
if ( isTranslationAvailable )
|
||||||
CalamaresUtils::installTranslator( selectedLocale.name(),
|
CalamaresUtils::installTranslator( matchedLocale.name(),
|
||||||
Calamares::Branding::instance()->translationsPathPrefix(),
|
Calamares::Branding::instance()->translationsPathPrefix(),
|
||||||
qApp );
|
qApp );
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user