[welcome] Start up in more-specific system language
Because of the way Qt interprets the environment variable LANG, using `sr@latin` or `sr@latn` or `ca@valencia` would get you `sr` or `ca`, respectively, which isn't an exact match. Now that Translation has special-handling for those values of LANG, match with the ID first. This allows starting Calamares in Serbian (Latin script) or Catalan (Valencia) for locales that need it. (Qt doesn't recognize ca@valencia as a variant, since that's a region- based locale, not country- or script-based)
This commit is contained in:
parent
792c4914b0
commit
8aa8597ab0
@ -121,26 +121,35 @@ void
|
||||
Config::initLanguages()
|
||||
{
|
||||
// Find the best initial translation
|
||||
QLocale defaultLocale = QLocale( QLocale::system().name() );
|
||||
CalamaresUtils::Locale::Translation defaultTranslation;
|
||||
|
||||
cDebug() << "Matching locale" << defaultLocale;
|
||||
int matchedLocaleIndex = m_languages->find( [&]( const QLocale& x ) {
|
||||
return x.language() == defaultLocale.language() && x.country() == defaultLocale.country();
|
||||
} );
|
||||
cDebug() << "Trying to match locale" << defaultTranslation.id();
|
||||
int matchedLocaleIndex = m_languages->find( defaultTranslation.id() );
|
||||
|
||||
// Need to match by some other means than the exact translation Id
|
||||
if ( matchedLocaleIndex < 0 )
|
||||
{
|
||||
|
||||
QLocale defaultLocale = defaultTranslation.locale();
|
||||
|
||||
cDebug() << "Trying to match locale" << defaultLocale;
|
||||
matchedLocaleIndex = m_languages->find(
|
||||
[ & ]( const QLocale& x )
|
||||
{ return x.language() == defaultLocale.language() && x.country() == defaultLocale.country(); } );
|
||||
|
||||
if ( matchedLocaleIndex < 0 )
|
||||
{
|
||||
cDebug() << Logger::SubEntry << "Matching approximate locale" << defaultLocale.language();
|
||||
cDebug() << Logger::SubEntry << "Trying to match approximate locale" << defaultLocale.language();
|
||||
|
||||
matchedLocaleIndex
|
||||
= m_languages->find( [&]( const QLocale& x ) { return x.language() == defaultLocale.language(); } );
|
||||
= m_languages->find( [ & ]( const QLocale& x ) { return x.language() == defaultLocale.language(); } );
|
||||
}
|
||||
|
||||
if ( matchedLocaleIndex < 0 )
|
||||
{
|
||||
QLocale en_us( QLocale::English, QLocale::UnitedStates );
|
||||
|
||||
cDebug() << Logger::SubEntry << "Matching English (US)";
|
||||
cDebug() << Logger::SubEntry << "Trying to match English (US)";
|
||||
matchedLocaleIndex = m_languages->find( en_us );
|
||||
|
||||
// Now, if it matched, because we didn't match the system locale, switch to the one found
|
||||
@ -149,6 +158,7 @@ Config::initLanguages()
|
||||
QLocale::setDefault( m_languages->locale( matchedLocaleIndex ).locale() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( matchedLocaleIndex >= 0 )
|
||||
{
|
||||
@ -156,7 +166,7 @@ Config::initLanguages()
|
||||
}
|
||||
else
|
||||
{
|
||||
cWarning() << "No available translation matched" << defaultLocale;
|
||||
cWarning() << "No available translation matched" << defaultTranslation.id() << defaultTranslation.locale();
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,7 +201,8 @@ Config::setLocaleIndex( int index )
|
||||
|
||||
QLocale::setDefault( selectedTranslation.locale() );
|
||||
const auto* branding = Calamares::Branding::instance();
|
||||
CalamaresUtils::installTranslator( selectedTranslation.id(), branding ? branding->translationsDirectory() : QString() );
|
||||
CalamaresUtils::installTranslator( selectedTranslation.id(),
|
||||
branding ? branding->translationsDirectory() : QString() );
|
||||
if ( Calamares::JobQueue::instance() && Calamares::JobQueue::instance()->globalStorage() )
|
||||
{
|
||||
CalamaresUtils::Locale::insertGS( *Calamares::JobQueue::instance()->globalStorage(),
|
||||
@ -367,7 +378,10 @@ setGeoIP( Config* config, const QVariantMap& configurationMap )
|
||||
if ( handler->type() != CalamaresUtils::GeoIP::Handler::Type::None )
|
||||
{
|
||||
auto* future = new FWString();
|
||||
QObject::connect( future, &FWString::finished, [config, future, handler]() {
|
||||
QObject::connect( future,
|
||||
&FWString::finished,
|
||||
[ config, future, handler ]()
|
||||
{
|
||||
QString countryResult = future->future().result();
|
||||
cDebug() << "GeoIP result for welcome=" << countryResult;
|
||||
::setCountry( config, countryResult, handler );
|
||||
|
Loading…
Reference in New Issue
Block a user