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:
parent
58e7e7c006
commit
854c19f305
@ -43,6 +43,8 @@ GreetingPage::GreetingPage( QWidget* parent )
|
|||||||
|
|
||||||
QString defaultLocale = QLocale::system().name();
|
QString defaultLocale = QLocale::system().name();
|
||||||
{
|
{
|
||||||
|
bool isTranslationAvailable = false;
|
||||||
|
|
||||||
foreach ( const QString& locale, QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') )
|
foreach ( const QString& locale, QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') )
|
||||||
{
|
{
|
||||||
QLocale thisLocale = QLocale( locale );
|
QLocale thisLocale = QLocale( locale );
|
||||||
@ -56,10 +58,40 @@ GreetingPage::GreetingPage( QWidget* parent )
|
|||||||
->setData( Qt::UserRole, thisLocale );
|
->setData( Qt::UserRole, thisLocale );
|
||||||
if ( thisLocale.language() == QLocale( defaultLocale ).language() &&
|
if ( thisLocale.language() == QLocale( defaultLocale ).language() &&
|
||||||
thisLocale.country() == QLocale( defaultLocale ).country() )
|
thisLocale.country() == QLocale( defaultLocale ).country() )
|
||||||
|
{
|
||||||
|
isTranslationAvailable = true;
|
||||||
ui->languageWidget->setCurrentRow( ui->languageWidget->count() - 1 );
|
ui->languageWidget->setCurrentRow( ui->languageWidget->count() - 1 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ui->languageWidget->sortItems();
|
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,
|
connect( ui->languageWidget, &QListWidget::currentItemChanged,
|
||||||
this, [ & ]( QListWidgetItem *current, QListWidgetItem *previous )
|
this, [ & ]( QListWidgetItem *current, QListWidgetItem *previous )
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user