[libcalamares] Add get() to the string
- Look up the translation of the requested string with the current or a specific locale. This implementation is a stub. - Add tests for the getter.
This commit is contained in:
parent
e0edd1f3e2
commit
50d74c4eca
@ -109,10 +109,16 @@ void LocaleTests::testTranslatableConfig1()
|
|||||||
CalamaresUtils::Locale::TranslatedString ts1( "Hello" );
|
CalamaresUtils::Locale::TranslatedString ts1( "Hello" );
|
||||||
QCOMPARE( ts1.count(), 1 );
|
QCOMPARE( ts1.count(), 1 );
|
||||||
|
|
||||||
|
QCOMPARE( ts1.get(), "Hello" );
|
||||||
|
QCOMPARE( ts1.get( QLocale("nl")), "Hello" );
|
||||||
|
|
||||||
QVariantMap map;
|
QVariantMap map;
|
||||||
map.insert( "description", "description (no language)" );
|
map.insert( "description", "description (no language)" );
|
||||||
CalamaresUtils::Locale::TranslatedString ts2(map, "description");
|
CalamaresUtils::Locale::TranslatedString ts2(map, "description");
|
||||||
QCOMPARE( ts2.count(), 1 );
|
QCOMPARE( ts2.count(), 1 );
|
||||||
|
|
||||||
|
QCOMPARE( ts2.get(), "description (no language)");
|
||||||
|
QCOMPARE( ts2.get( QLocale( "nl" ) ), "description (no language)");
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocaleTests::testTranslatableConfig2()
|
void LocaleTests::testTranslatableConfig2()
|
||||||
@ -132,6 +138,9 @@ void LocaleTests::testTranslatableConfig2()
|
|||||||
// The +1 is because "" is always also inserted
|
// The +1 is because "" is always also inserted
|
||||||
QCOMPARE( ts1.count(), someLanguages().count()+1 );
|
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");
|
CalamaresUtils::Locale::TranslatedString ts2(map, "name");
|
||||||
// We skipped dutch this time
|
// We skipped dutch this time
|
||||||
QCOMPARE( ts2.count(), someLanguages().count() );
|
QCOMPARE( ts2.count(), someLanguages().count() );
|
||||||
|
@ -53,7 +53,6 @@ TranslatedString::TranslatedString(const QVariantMap& map, const QString& key)
|
|||||||
}
|
}
|
||||||
else if ( subkey.startsWith( key ) )
|
else if ( subkey.startsWith( key ) )
|
||||||
{
|
{
|
||||||
cDebug() << "Checking" << subkey;
|
|
||||||
QRegularExpressionMatch match;
|
QRegularExpressionMatch match;
|
||||||
if ( subkey.indexOf( QRegularExpression("\\[([a-zA-Z_@]*)\\]"), 0, &match ) > 0 )
|
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 Locale
|
||||||
} // namespace CalamaresUtils
|
} // namespace CalamaresUtils
|
||||||
|
@ -47,6 +47,12 @@ namespace Locale
|
|||||||
|
|
||||||
int count() const { return m_strings.count(); }
|
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:
|
private:
|
||||||
// Maps locale name to human-readable string, "" is English
|
// Maps locale name to human-readable string, "" is English
|
||||||
QMap< QString, QString > m_strings;
|
QMap< QString, QString > m_strings;
|
||||||
|
Loading…
Reference in New Issue
Block a user