From 764c775f08e77a3eb66209edc2a6bb1e54dafa77 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 6 Aug 2019 00:05:24 +0200 Subject: [PATCH] [libcalamares] Tighten tests, add special case - The tests should be run in C locale, otherwise the plain get() function uses the current locale, which will fail (e.g. running LANG=nl ./libcalamareslocaletest returns the Dutch strings for plain get, which isn't what we expect). - sr@latin is still special. --- src/libcalamares/locale/Tests.cpp | 16 ++++++++++++++++ .../locale/TranslatableConfiguration.cpp | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/src/libcalamares/locale/Tests.cpp b/src/libcalamares/locale/Tests.cpp index 6f8310233..241d66bbd 100644 --- a/src/libcalamares/locale/Tests.cpp +++ b/src/libcalamares/locale/Tests.cpp @@ -108,6 +108,7 @@ LocaleTests::testTranslatableLanguages() void LocaleTests::testTranslatableConfig1() { + QCOMPARE( QLocale().name(), "C" ); // Otherwise plain get() is dubious CalamaresUtils::Locale::TranslatedString ts1( "Hello" ); QCOMPARE( ts1.count(), 1 ); @@ -126,6 +127,7 @@ LocaleTests::testTranslatableConfig1() void LocaleTests::testTranslatableConfig2() { + QCOMPARE( QLocale().name(), "C" ); // Otherwise plain get() is dubious QVariantMap map; for ( const auto& language : someLanguages() ) @@ -144,6 +146,20 @@ LocaleTests::testTranslatableConfig2() QCOMPARE( ts1.get(), "description" ); // it wasn't set QCOMPARE( ts1.get( QLocale( "nl" ) ), "description (language nl)" ); + for ( const auto& language : someLanguages() ) + { + // Skip Serbian (latin) because QLocale() constructed with it + // doesn't retain the @latin part. + if ( language == "sr@latin" ) + { + continue; + } + // Could be QVERIFY, but then we don't see what language code fails + QCOMPARE( ts1.get( language ) == QString( "description (language %1)" ).arg( language ) ? language : QString(), + language ); + } + QCOMPARE( ts1.get( QLocale( QLocale::Language::Serbian, QLocale::Script::LatinScript, QLocale::Country::Serbia ) ), + "description (language sr@latin)" ); CalamaresUtils::Locale::TranslatedString ts2( map, "name" ); // We skipped dutch this time diff --git a/src/libcalamares/locale/TranslatableConfiguration.cpp b/src/libcalamares/locale/TranslatableConfiguration.cpp index 0b4a6ff71..82923a5fa 100644 --- a/src/libcalamares/locale/TranslatableConfiguration.cpp +++ b/src/libcalamares/locale/TranslatableConfiguration.cpp @@ -73,6 +73,12 @@ QString TranslatedString::get( const QLocale& locale ) const { QString localeName = locale.name(); + // Special case, sr@latin doesn't have the @latin reflected in the name + if ( locale.language() == QLocale::Language::Serbian && locale.script() == QLocale::Script::LatinScript ) + { + localeName = QStringLiteral( "sr@latin" ); + } + cDebug() << "Getting locale" << localeName; if ( m_strings.contains( localeName ) ) {