From 0a526febae9cfe761cb427c285165fc1a07c8dff Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 8 Jan 2019 11:39:15 +0100 Subject: [PATCH] [locale] Refactor setting the BCP47 name and update test --- src/modules/locale/LocaleConfiguration.cpp | 17 ++++++++++++----- src/modules/locale/LocaleConfiguration.h | 8 ++++++++ src/modules/locale/Tests.cpp | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/modules/locale/LocaleConfiguration.cpp b/src/modules/locale/LocaleConfiguration.cpp index f980b850c..ca0a707ad 100644 --- a/src/modules/locale/LocaleConfiguration.cpp +++ b/src/modules/locale/LocaleConfiguration.cpp @@ -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 ) diff --git a/src/modules/locale/LocaleConfiguration.h b/src/modules/locale/LocaleConfiguration.h index a4753e221..95dadd5c3 100644 --- a/src/modules/locale/LocaleConfiguration.h +++ b/src/modules/locale/LocaleConfiguration.h @@ -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; }; diff --git a/src/modules/locale/Tests.cpp b/src/modules/locale/Tests.cpp index 32a10e250..6cad2ef74 100644 --- a/src/modules/locale/Tests.cpp +++ b/src/modules/locale/Tests.cpp @@ -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" ); }