[locale] Refactor setting the BCP47 name and update test
This commit is contained in:
parent
b1921cced9
commit
0a526febae
@ -30,9 +30,19 @@ LocaleConfiguration::LocaleConfiguration()
|
||||
LocaleConfiguration::LocaleConfiguration( const QString& localeName )
|
||||
: LocaleConfiguration()
|
||||
{
|
||||
lang = lc_numeric = lc_time = lc_monetary = lc_paper = lc_name
|
||||
lc_numeric = lc_time = lc_monetary = lc_paper = lc_name
|
||||
= lc_address = lc_telephone = lc_measurement
|
||||
= lc_identification = localeName;
|
||||
|
||||
(void) setLanguage( localeName );
|
||||
}
|
||||
|
||||
QString
|
||||
LocaleConfiguration::setLanguage(const QString& localeName )
|
||||
{
|
||||
QString language = localeName.split( '_' ).first();
|
||||
myLanguageLocaleBcp47 = QLocale( language ).bcp47Name().toLower();
|
||||
return language;
|
||||
}
|
||||
|
||||
|
||||
@ -42,10 +52,7 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale,
|
||||
const QString& countryCode )
|
||||
{
|
||||
LocaleConfiguration lc;
|
||||
|
||||
// Note that the documentation how this works is in packages.conf
|
||||
QString language = languageLocale.split( '_' ).first();
|
||||
lc.myLanguageLocaleBcp47 = QLocale(language).bcp47Name().toLower();
|
||||
QString language = lc.setLanguage( languageLocale );
|
||||
|
||||
QStringList linesForLanguage;
|
||||
for ( const QString &line : availableLocales )
|
||||
|
@ -51,6 +51,14 @@ public:
|
||||
bool explicit_lang, explicit_lc;
|
||||
|
||||
private:
|
||||
/** @brief sets lang and the BCP47 representation
|
||||
*
|
||||
* Note that the documentation how this works is in packages.conf
|
||||
*
|
||||
* @return The language part of the locale (e.g. before _)
|
||||
*/
|
||||
QString setLanguage( const QString& localeName );
|
||||
|
||||
QString myLanguageLocaleBcp47;
|
||||
};
|
||||
|
||||
|
@ -49,5 +49,5 @@ void LocaleTests::testDefaultLocaleConfiguration()
|
||||
{
|
||||
LocaleConfiguration lc( "en_US.UTF-8" );
|
||||
QVERIFY( !lc.isEmpty() );
|
||||
QCOMPARE( lc.toBcp47(), "en_US" );
|
||||
QCOMPARE( lc.toBcp47(), "en" );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user