From a9ef1523fff459aa6e78f409d8fc15e9e373bb93 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Mon, 6 Jun 2022 01:24:25 +0300 Subject: [PATCH] kdecore: remove old QTranslator virtual method overload Signed-off-by: Ivailo Monev --- kdecore/kernel/kglobal_p.h | 17 ++---------- kdecore/localization/klocale.cpp | 4 +-- kdecore/localization/klocale.h | 2 +- kdecore/localization/klocale_kde.cpp | 38 ++++++-------------------- kdecore/localization/klocale_p.h | 2 +- kdecore/tests/klocalizedstringtest.cpp | 2 +- 6 files changed, 16 insertions(+), 49 deletions(-) diff --git a/kdecore/kernel/kglobal_p.h b/kdecore/kernel/kglobal_p.h index 7fd55e2e..b2d1d2db 100644 --- a/kdecore/kernel/kglobal_p.h +++ b/kdecore/kernel/kglobal_p.h @@ -43,23 +43,12 @@ public: setObjectName(QLatin1String("kdetranslator")); } - // provides virtuals for old and new method - virtual QString translate(const char *context, - const char *sourceText) const + QString translate(const char *context, const char *sourceText) const final { - return KGlobal::locale()->translateQt(context, sourceText, 0); + return KGlobal::locale()->translateQt(context, sourceText); } - virtual QString translate(const char *context, - const char *sourceText, - const char *message, - const char *disambiguation = 0) const - { - Q_UNUSED(disambiguation); - return KGlobal::locale()->translateQt(context, sourceText, message); - } - - virtual bool isEmpty() const + bool isEmpty() const final { return false; } diff --git a/kdecore/localization/klocale.cpp b/kdecore/localization/klocale.cpp index 2d5c1660..9e040c4f 100644 --- a/kdecore/localization/klocale.cpp +++ b/kdecore/localization/klocale.cpp @@ -175,9 +175,9 @@ void KLocale::translateRaw(const char *ctxt, const char *singular, const char *p d->translateRawFrom(0, ctxt, singular, plural, n, lang, trans); } -QString KLocale::translateQt(const char *context, const char *sourceText, const char *comment) const +QString KLocale::translateQt(const char *context, const char *sourceText) const { - return d->translateQt(context, sourceText, comment); + return d->translateQt(context, sourceText); } QList KLocale::allDigitSetsList() const diff --git a/kdecore/localization/klocale.h b/kdecore/localization/klocale.h index 7eb8edba..2c5ae6b1 100644 --- a/kdecore/localization/klocale.h +++ b/kdecore/localization/klocale.h @@ -1788,7 +1788,7 @@ public: * The parameters are similar to i18n(), but the result * value has other semantics (it can be QString()) */ - QString translateQt(const char *context, const char *sourceText, const char *comment) const; + QString translateQt(const char *context, const char *sourceText) const; /** * Provides list of all known language codes. diff --git a/kdecore/localization/klocale_kde.cpp b/kdecore/localization/klocale_kde.cpp index 30efd391..354dac25 100644 --- a/kdecore/localization/klocale_kde.cpp +++ b/kdecore/localization/klocale_kde.cpp @@ -966,29 +966,13 @@ void KLocalePrivate::translateRawFrom(const char *catname, const char *msgctxt, } } -QString KLocalePrivate::translateQt(const char *context, const char *sourceText, const char *comment) const +QString KLocalePrivate::translateQt(const char *context, const char *sourceText) const { - // Qt's context is normally the name of the class of the method which makes + // Katie's context is normally the name of the class of the method which makes // the tr(sourceText) call. However, it can also be manually supplied via // translate(context, sourceText) call. // - // Qt's sourceText is the actual message displayed to the user. - // - // Qt's comment is an optional argument of tr() and translate(), like - // tr(sourceText, comment) and translate(context, sourceText, comment). - // - // We handle this in the following way: - // - // If the comment is given, then it is considered gettext's msgctxt, so a - // context call is made. - // - // If the comment is not given, but context is given, then we treat it as - // msgctxt only if it was manually supplied (the one in translate()) -- but - // we don't know this, so we first try a context call, and if translation - // is not found, we fallback to ordinary call. - // - // If neither comment nor context are given, it's just an ordinary call - // on sourceText. + // Katie's sourceText is the actual message displayed to the user. if (!sourceText || !sourceText[0]) { kDebug(173) << "KLocale: trying to look up \"\" in catalog. " @@ -1006,17 +990,11 @@ QString KLocalePrivate::translateQt(const char *context, const char *sourceText, // NOTE: Condition (language != defaultLanguage()) means that translation // was found, otherwise we got the original string back as translation. - if (comment && comment[0]) { - // Comment given, go for context call. - translateRawFrom(0, comment, sourceText, 0, 0, &language, &translation); - } else { - // Comment not given, go for try-fallback with context. - if (context && context[0]) { - translateRawFrom(0, context, sourceText, 0, 0, &language, &translation); - } - if (language.isEmpty() || language == defaultLanguage()) { - translateRawFrom(0, 0, sourceText, 0, 0, &language, &translation); - } + if (context && context[0]) { + translateRawFrom(0, context, sourceText, 0, 0, &language, &translation); + } + if (language.isEmpty() || language == defaultLanguage()) { + translateRawFrom(0, 0, sourceText, 0, 0, &language, &translation); } if (language != defaultLanguage()) { diff --git a/kdecore/localization/klocale_p.h b/kdecore/localization/klocale_p.h index fe514c22..e416fdea 100644 --- a/kdecore/localization/klocale_p.h +++ b/kdecore/localization/klocale_p.h @@ -318,7 +318,7 @@ public: * @internal Translates a message as a QTranslator is supposed to. * The worker of the same-name KLocale API function. */ - QString translateQt(const char *context, const char *sourceText, const char *comment) const; + QString translateQt(const char *context, const char *sourceText) const; /** * @internal Checks whether or not the active catalog is found for the given language. diff --git a/kdecore/tests/klocalizedstringtest.cpp b/kdecore/tests/klocalizedstringtest.cpp index 0243bc99..b163c27d 100644 --- a/kdecore/tests/klocalizedstringtest.cpp +++ b/kdecore/tests/klocalizedstringtest.cpp @@ -223,7 +223,7 @@ void KLocalizedStringTest::translateToFrench() void KLocalizedStringTest::translateQt() { - QString result = KGlobal::locale()->translateQt("QPrintPreviewDialog", "Landscape", 0); + QString result = KGlobal::locale()->translateQt("QPrintPreviewDialog", "Landscape"); // When we use the default language, translateQt returns an empty string. QString expected = m_hasFrench ? QString("Paysage") : QString(); QCOMPARE(result, expected);