[libcalamares] Follow deprecations in QLocale
Prefer territory() over country() in Qt 6.6 and later.
This commit is contained in:
parent
196f85fa2c
commit
2fcc008d7b
@ -12,6 +12,7 @@
|
||||
#include "Translation.h"
|
||||
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -145,6 +146,44 @@ specialCaseSystemLanguage()
|
||||
{ return ( s.language == language ) && lookup_region( region, s.regions ); } );
|
||||
return ( it != std::cend( special_cases ) ) ? QString::fromLatin1( it->id ) : QString();
|
||||
}
|
||||
|
||||
///@brief Country (territory) name for this locale
|
||||
QString
|
||||
territoryName( const QLocale& locale )
|
||||
{
|
||||
#if QT_VERSION < QT_VERSION_CHECK( 6, 6, 0 )
|
||||
return QLocale::countryToString( locale.country() );
|
||||
#else
|
||||
return QLocale::territoryToString( locale.territory() );
|
||||
#endif
|
||||
}
|
||||
|
||||
QString
|
||||
nativeTerritoryName( const QLocale& locale )
|
||||
{
|
||||
#if QT_VERSION < QT_VERSION_CHECK( 6, 6, 0 )
|
||||
return locale.nativeCountryName();
|
||||
#else
|
||||
return locale.nativeTerritoryName();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
needsTerritorialDisambiguation( const QLocale& locale )
|
||||
{
|
||||
#if QT_VERSION < QT_VERSION_CHECK( 6, 6, 0 )
|
||||
return QLocale::countriesForLanguage( locale.language() ).count() > 1;
|
||||
#else
|
||||
std::set<QLocale::Territory> s;
|
||||
for(const auto & l : QLocale::matchingLocales( locale.language(), QLocale::Script::AnyScript, QLocale::Territory::AnyTerritory ))
|
||||
{
|
||||
s.insert(l.territory());
|
||||
}
|
||||
return s.size() > 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace Calamares
|
||||
@ -178,12 +217,10 @@ Translation::Translation( const Id& localeId, LabelFormat format, QObject* paren
|
||||
}
|
||||
|
||||
bool needsCountryName = ( format == LabelFormat::AlwaysWithCountry )
|
||||
|| ( !name && localeId.name.contains( '_' )
|
||||
&& QLocale::countriesForLanguage( m_locale.language() ).count() > 1 );
|
||||
QString countryName = needsCountryName ? m_locale.nativeCountryName() : QString();
|
||||
|| ( !name && localeId.name.contains( '_' ) && needsTerritorialDisambiguation( ( m_locale ) ) );
|
||||
const QString countryName = needsCountryName ? nativeTerritoryName( m_locale ) : QString();
|
||||
m_label = needsCountryName ? longFormat.arg( languageName, countryName ) : languageName;
|
||||
m_englishLabel = needsCountryName ? longFormat.arg( englishName, QLocale::countryToString( m_locale.country() ) )
|
||||
: englishName;
|
||||
m_englishLabel = needsCountryName ? longFormat.arg( englishName, territoryName( m_locale ) ) : englishName;
|
||||
}
|
||||
|
||||
QLocale
|
||||
|
@ -105,7 +105,15 @@ public:
|
||||
QLocale::Language language() const { return m_locale.language(); }
|
||||
|
||||
/// @brief Convenience accessor to the country part (if any) of the locale
|
||||
QLocale::Country country() const { return m_locale.country(); }
|
||||
QLocale::Country country() const
|
||||
{
|
||||
#if QT_VERSION < QT_VERSION_CHECK( 6, 6, 0 )
|
||||
|
||||
return m_locale.country();
|
||||
#else
|
||||
return m_locale.territory();
|
||||
#endif
|
||||
}
|
||||
|
||||
/** @brief Get a Qt locale for the given @p localeName
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user