Fix defaulting to first langauge in the list when language and country is not available.

- When it doesnt find a match for a language and a country, find the first value that only matches language.
- If this also fails, default to english.
This commit is contained in:
Ramon Buldó 2015-01-18 14:56:46 +01:00
parent 58e7e7c006
commit 854c19f305

View File

@ -43,6 +43,8 @@ GreetingPage::GreetingPage( QWidget* parent )
QString defaultLocale = QLocale::system().name();
{
bool isTranslationAvailable = false;
foreach ( const QString& locale, QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') )
{
QLocale thisLocale = QLocale( locale );
@ -56,10 +58,40 @@ GreetingPage::GreetingPage( QWidget* parent )
->setData( Qt::UserRole, thisLocale );
if ( thisLocale.language() == QLocale( defaultLocale ).language() &&
thisLocale.country() == QLocale( defaultLocale ).country() )
{
isTranslationAvailable = true;
ui->languageWidget->setCurrentRow( ui->languageWidget->count() - 1 );
}
}
ui->languageWidget->sortItems();
if ( !isTranslationAvailable )
{
for (int i = 0; i < ui->languageWidget->count(); i++)
{
QLocale thisLocale = ui->languageWidget->item(i)->data( Qt::UserRole ).toLocale();
if ( thisLocale.language() == QLocale( defaultLocale ).language() )
{
isTranslationAvailable = true;
ui->languageWidget->setCurrentRow( i );
break;
}
}
}
if ( !isTranslationAvailable )
{
for (int i = 0; i < ui->languageWidget->count(); i++)
{
QLocale thisLocale = ui->languageWidget->item(i)->data( Qt::UserRole ).toLocale();
if ( thisLocale == QLocale( QLocale::English, QLocale::UnitedStates ) )
{
ui->languageWidget->setCurrentRow( i );
break;
}
}
}
connect( ui->languageWidget, &QListWidget::currentItemChanged,
this, [ & ]( QListWidgetItem *current, QListWidgetItem *previous )
{