[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 "Translation.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@ -145,6 +146,44 @@ specialCaseSystemLanguage()
|
|||||||
{ return ( s.language == language ) && lookup_region( region, s.regions ); } );
|
{ return ( s.language == language ) && lookup_region( region, s.regions ); } );
|
||||||
return ( it != std::cend( special_cases ) ) ? QString::fromLatin1( it->id ) : QString();
|
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
|
||||||
|
|
||||||
namespace Calamares
|
namespace Calamares
|
||||||
@ -178,12 +217,10 @@ Translation::Translation( const Id& localeId, LabelFormat format, QObject* paren
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool needsCountryName = ( format == LabelFormat::AlwaysWithCountry )
|
bool needsCountryName = ( format == LabelFormat::AlwaysWithCountry )
|
||||||
|| ( !name && localeId.name.contains( '_' )
|
|| ( !name && localeId.name.contains( '_' ) && needsTerritorialDisambiguation( ( m_locale ) ) );
|
||||||
&& QLocale::countriesForLanguage( m_locale.language() ).count() > 1 );
|
const QString countryName = needsCountryName ? nativeTerritoryName( m_locale ) : QString();
|
||||||
QString countryName = needsCountryName ? m_locale.nativeCountryName() : QString();
|
|
||||||
m_label = needsCountryName ? longFormat.arg( languageName, countryName ) : languageName;
|
m_label = needsCountryName ? longFormat.arg( languageName, countryName ) : languageName;
|
||||||
m_englishLabel = needsCountryName ? longFormat.arg( englishName, QLocale::countryToString( m_locale.country() ) )
|
m_englishLabel = needsCountryName ? longFormat.arg( englishName, territoryName( m_locale ) ) : englishName;
|
||||||
: englishName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QLocale
|
QLocale
|
||||||
|
@ -105,7 +105,15 @@ public:
|
|||||||
QLocale::Language language() const { return m_locale.language(); }
|
QLocale::Language language() const { return m_locale.language(); }
|
||||||
|
|
||||||
/// @brief Convenience accessor to the country part (if any) of the locale
|
/// @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
|
/** @brief Get a Qt locale for the given @p localeName
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user