diff --git a/src/libcalamares/locale/Tests.cpp b/src/libcalamares/locale/Tests.cpp index 46b1df150..1cfd733a0 100644 --- a/src/libcalamares/locale/Tests.cpp +++ b/src/libcalamares/locale/Tests.cpp @@ -109,10 +109,16 @@ void LocaleTests::testTranslatableConfig1() CalamaresUtils::Locale::TranslatedString ts1( "Hello" ); QCOMPARE( ts1.count(), 1 ); + QCOMPARE( ts1.get(), "Hello" ); + QCOMPARE( ts1.get( QLocale("nl")), "Hello" ); + QVariantMap map; map.insert( "description", "description (no language)" ); CalamaresUtils::Locale::TranslatedString ts2(map, "description"); QCOMPARE( ts2.count(), 1 ); + + QCOMPARE( ts2.get(), "description (no language)"); + QCOMPARE( ts2.get( QLocale( "nl" ) ), "description (no language)"); } void LocaleTests::testTranslatableConfig2() @@ -131,6 +137,9 @@ void LocaleTests::testTranslatableConfig2() CalamaresUtils::Locale::TranslatedString ts1(map, "description"); // The +1 is because "" is always also inserted QCOMPARE( ts1.count(), someLanguages().count()+1 ); + + QCOMPARE( ts1.get(), "description"); // it wasn't set + QCOMPARE( ts1.get( QLocale( "nl" ) ), "description (language nl)"); 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 d6c078303..d7066a57c 100644 --- a/src/libcalamares/locale/TranslatableConfiguration.cpp +++ b/src/libcalamares/locale/TranslatableConfiguration.cpp @@ -53,7 +53,6 @@ TranslatedString::TranslatedString(const QVariantMap& map, const QString& key) } else if ( subkey.startsWith( key ) ) { - cDebug() << "Checking" << subkey; QRegularExpressionMatch match; if ( subkey.indexOf( QRegularExpression("\\[([a-zA-Z_@]*)\\]"), 0, &match ) > 0 ) { @@ -64,5 +63,17 @@ TranslatedString::TranslatedString(const QVariantMap& map, const QString& key) } } +QString TranslatedString::get() const +{ + return get( QLocale() ); +} + +QString TranslatedString::get(const QLocale& locale) const +{ + cDebug() << "Getting locale" << locale.name(); + return m_strings[QString()]; +} + + } // namespace Locale } // namespace CalamaresUtils diff --git a/src/libcalamares/locale/TranslatableConfiguration.h b/src/libcalamares/locale/TranslatableConfiguration.h index 01bdf8ed6..b5a18ee73 100644 --- a/src/libcalamares/locale/TranslatableConfiguration.h +++ b/src/libcalamares/locale/TranslatableConfiguration.h @@ -47,6 +47,12 @@ namespace Locale int count() const { return m_strings.count(); } + /// @brief Gets the string in the current locale + QString get() const; + + /// @brief Gets the string from the given locale + QString get(const QLocale&) const; + private: // Maps locale name to human-readable string, "" is English QMap< QString, QString > m_strings;