[libcalamares, keyboard] Use convenience for getting current locale

This commit is contained in:
Adriaan de Groot 2022-06-18 00:40:26 +02:00
parent d80661211c
commit 2478570deb
2 changed files with 13 additions and 16 deletions

View File

@ -13,6 +13,7 @@
#include "GlobalStorage.h"
#include "JobQueue.h"
#include "PythonHelper.h"
#include "locale/Global.h"
#include "partition/Mount.h"
#include "utils/CalamaresUtilsSystem.h"
#include "utils/Logger.h"
@ -280,24 +281,19 @@ _gettext_languages()
Calamares::GlobalStorage* gs
= jq ? jq->globalStorage() : CalamaresPython::GlobalStoragePythonWrapper::globalStorageInstance();
QVariant localeConf_ = gs->value( "localeConf" );
if ( localeConf_.canConvert< QVariantMap >() )
QString lang = CalamaresUtils::Locale::readGS( *gs, QStringLiteral( "LANG" ) );
if ( !lang.isEmpty() )
{
QVariant lang_ = localeConf_.value< QVariantMap >()[ "LANG" ];
if ( lang_.canConvert< QString >() )
languages.append( lang );
if ( lang.indexOf( '.' ) > 0 )
{
QString lang = lang_.value< QString >();
lang.truncate( lang.indexOf( '.' ) );
languages.append( lang );
}
if ( lang.indexOf( '_' ) > 0 )
{
lang.truncate( lang.indexOf( '_' ) );
languages.append( lang );
if ( lang.indexOf( '.' ) > 0 )
{
lang.truncate( lang.indexOf( '.' ) );
languages.append( lang );
}
if ( lang.indexOf( '_' ) > 0 )
{
lang.truncate( lang.indexOf( '_' ) );
languages.append( lang );
}
}
}
return languages;

View File

@ -15,6 +15,7 @@
#include "GlobalStorage.h"
#include "JobQueue.h"
#include "locale/Global.h"
#include "utils/Logger.h"
#include "utils/RAII.h"
#include "utils/Retranslator.h"
@ -483,7 +484,7 @@ Config::guessLocaleKeyboardLayout()
// Try to preselect a layout, depending on language and locale
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
QString lang = gs->value( "localeConf" ).toMap().value( "LANG" ).toString();
QString lang = CalamaresUtils::Locale::readGS( *gs, QStringLiteral( "LANG" ) );
cDebug() << "Got locale language" << lang;
if ( !lang.isEmpty() )