Disable loading of translations when using 'C' locale
AbandonedPublic

Authored by habacker on Aug 13 2018, 8:39 AM.

Details

Reviewers
apol
Group Reviewers
Frameworks
Summary

kcoreaddons test case 'kformattest' is designed not to use translations
and fails if a translation of kcoreaddons is installed.
To disable translations, QLocale::setDefault(QLocale::C) can now be called before
instantiating Q[Core]Application.

CCBUG: 397404

Diff Detail

Repository
R240 Extra CMake Modules
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 1755
Build 1773: arc lint + arc unit
habacker created this revision.Aug 13 2018, 8:39 AM
Restricted Application added projects: Frameworks, Build System. · View Herald TranscriptAug 13 2018, 8:39 AM
Restricted Application added subscribers: kde-buildsystem, kde-frameworks-devel. · View Herald Transcript
habacker requested review of this revision.Aug 13 2018, 8:39 AM
ngraham edited the summary of this revision. (Show Details)Aug 13 2018, 8:53 AM
ngraham added reviewers: Frameworks, apol.
aacid added a subscriber: aacid.Aug 13 2018, 9:19 AM

Doesn't setting the locale to en solve the same problem without needing to change ECM?

No, both LC_ALL=C and LC_ALL=en fetches the same english translation

~/src/kf5/kcoreaddons-build> LC_ALL=en strace -e trace=file bin/kformattest 2>&1 | grep \.qm | grep R_OK
access("/usr/share/locale/en/LC_MESSAGES/kcoreaddons5_qt.qm", R_OK) = 0

~/src/kf5/kcoreaddons-build> LC_ALL=C strace -e trace=file bin/kformattest 2>&1 | grep \.qm | grep R_OK
access("/usr/share/locale/en/LC_MESSAGES/kcoreaddons5_qt.qm", R_OK) = 0

The result is shown at https://bugs.kde.org/show_bug.cgi?id=397404#c0 (see below and with 'C' locale)

habacker added a comment.EditedAug 13 2018, 10:59 AM

Just as info:

kcoreaddons uses '(s)' suffix in its internal formating methods (https://cgit.kde.org/kcoreaddons.git/commit/src/lib/util/kformatprivate.cpp?id=ffcd094c1f4716a0d91650608e42017886a0a7e3) which is always translated with or without 's' (not always (s)) depending on the amount (see https://websvn.kde.org/trunk/l10n-kf5/en/messages/frameworks/kcoreaddons5_qt.po?revision=1522490&view=markup line 440ff)

aacid added a comment.Aug 14 2018, 9:24 AM

Honestly i think that test in kformattest is wrong and that it should contain it's own small minitranslation so that stuff works fine and then it should be

QCOMPARE(format.formatDecimalDuration(10), QStringLiteral("10 milliseconds"));

instead of

QCOMPARE(format.formatDecimalDuration(10), QStringLiteral("10 millisecond(s)"));
habacker abandoned this revision.Aug 14 2018, 11:11 AM

How to handle single/plural form then ?

QString KFormatPrivate::formatDecimalDuration(quint64 msecs, int decimalPlaces) const
{
...

//: @item:intext %1 is a whole number
//~ singular %n millisecond
//~ plural %n milliseconds
return tr("%n millisecond(s)", nullptr, msecs);

According to http://doc.qt.io/qt-5/i18n-source-translation.html the recent string usage seems to be exactly what is required.

From further inspection the solutions is to use translated reference values

  • QCOMPARE(format.formatDecimalDuration(10), QStringLiteral("10 millisecond(s)"));
  • QCOMPARE(format.formatDecimalDuration(10, 3), QStringLiteral("10 millisecond(s)"));

+ QCOMPARE(format.formatDecimalDuration(10), QCoreApplication::translate("KFormat", "%n millisecond(s)", nullptr, 10));
+ QCOMPARE(format.formatDecimalDuration(10, 3), QCoreApplication::translate("KFormat", "%n millisecond(s)", nullptr, 10));

Thanks for your feedback.