Bug 416247

Summary: KLocalizedString::toString not behaving as documented
Product: [Frameworks and Libraries] frameworks-ki18n Reporter: Harald Sitter <sitter>
Component: generalAssignee: Chusslove Illich <caslav.ilic>
Status: CONFIRMED ---    
Severity: normal CC: claudius.ellsel, kdelibs-bugs
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Harald Sitter 2020-01-14 13:27:16 UTC
SUMMARY
Documentation says "If \p languages is empty, original message is returned." which is not actually what's happening.

OBSERVED RESULT
`label.toString(QStringList());`

returns the localized string when I have LANGUAGE=de

EXPECTED RESULT
Returned value should be the original input string.

ADDITIONAL INFORMATION
The use case is in kinfocenter's about system module, which offers the ability to copy a textual dump to clipboard when the current system language is not english (i.e. an auto-untranslate feature if you will). Currently this is hardcoded but would be nice to just use KLS I suppose.
Comment 1 Claudius Ellsel 2020-06-15 19:53:11 UTC
Reproduced with https://invent.kde.org/plasma/kinfocenter/-/blob/master/Modules/about-distro/src/Entry.cpp#L43

Using an empty list as argument returns the German Strings for me.

Documentation: https://api.kde.org/frameworks/ki18n/html/classKLocalizedString.html

Probably relevant part of the implementation: https://api.kde.org/frameworks/ki18n/html/klocalizedstring_8cpp_source.html#l00530
Comment 2 ratijas 2022-05-02 18:47:36 UTC
*** Bug 453313 has been marked as a duplicate of this bug. ***
Comment 3 ratijas 2022-05-02 19:25:41 UTC
Still relevant today. I browsed source code, and tracked this problem down to the definition of `KFormatPrivate::formatByteSize`: it uses a bunch of unqualified tr() calls. The function tr() is declared by Q_DECLARE_TR_FUNCTIONS(KFormat), and delegates actual work to QCoreApplication::translate() which uses globally installed QTranslator object.