diff --git a/autotests/klocalizedstringtest.h b/autotests/klocalizedstringtest.h --- a/autotests/klocalizedstringtest.h +++ b/autotests/klocalizedstringtest.h @@ -44,6 +44,7 @@ void testLocalizedTranslator(); void semanticTags(); void multipleLanguages(); + void untranslatedText(); private: bool m_hasFrench; diff --git a/autotests/klocalizedstringtest.cpp b/autotests/klocalizedstringtest.cpp --- a/autotests/klocalizedstringtest.cpp +++ b/autotests/klocalizedstringtest.cpp @@ -572,6 +572,18 @@ QCOMPARE(i18n("Loadable modules"), QString::fromUtf8("Modules chargeables")); // The Catalan po doesn't have a translation so we get the English text } +void KLocalizedStringTest::untranslatedText() +{ + if (!m_hasFrench) { + QSKIP("French test files not usable."); + } + KLocalizedString s = ki18n("Job"); + KLocalizedString::setLanguages({"fr"}); + QCOMPARE(s.untranslatedText(), "Job"); + QCOMPARE(s.toString(), QString::fromUtf8("Tâche")); + QCOMPARE(s.untranslatedText(), "Job"); +} + #include #include diff --git a/src/klocalizedstring.h b/src/klocalizedstring.h --- a/src/klocalizedstring.h +++ b/src/klocalizedstring.h @@ -439,6 +439,13 @@ */ Q_REQUIRED_RESULT KLocalizedString ignoreMarkup() const; + /** + * Returns the untranslated text. + * + * \since 5.64 + */ + Q_REQUIRED_RESULT QByteArray untranslatedText() const; + /** * Set the given domain as application's main domain. * diff --git a/src/klocalizedstring.cpp b/src/klocalizedstring.cpp --- a/src/klocalizedstring.cpp +++ b/src/klocalizedstring.cpp @@ -1264,6 +1264,11 @@ return kls; } +QByteArray KLocalizedString::untranslatedText() const +{ + return d->text; +} + void KLocalizedString::setApplicationDomain(const char *domain) { KLocalizedStringPrivateStatics *s = staticsKLSP();