Locale-aware formatting of numbers on status bar
AbandonedPublic

Authored by huftis on May 30 2018, 5:08 PM.

Details

Summary

Numbers on the status bar (showing the number of
translated, fuzzy, untranslated &c. strings)
weren’t formatted using the number formatting settings
for the current locale. For example, the number 239097
was displayed as ‘239097’ instead of ‘239,097’ (in an
en-US locale) or ‘239 097’ (in a nn-NO locale).

With this patch, all numbers on the status bar
for 1) the project view and 2) the editor window are
now correctly formatted, making them easier to read.

BUG: 394866
FIXED-IN: 18.08

Test Plan

Before and after the patch:

  1. In Lokalize, open a translation project with a large

number (> 999) of files. (The project at trunk/l10n-support/nn
in SVN is a good candidate).

  1. Look at the status bar. Notice that large numbers

are missing the thousands separator (e.g. a comma or
space, depending on your locale) before the patch
but are properly formatted (i.e. with a thousands separator)
after the patch.

  1. Open a file that contains a large number of strings

(extragear-edu/kstars.po is a good candidate).
Notice the lack of proper formatting before the patch,
but proper formatting after the patch.

Diff Detail

Repository
R456 Lokalize
Branch
format-numbers-statusline (branched from Applications/18.08)
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 940
Build 953: arc lint + arc unit
huftis requested review of this revision.May 30 2018, 5:08 PM
huftis created this revision.
huftis added a comment.EditedMay 30 2018, 5:09 PM

Here are some before-and-after screenshots:

Project view (before):

Project view (after):

Editor (before):

Editor (after) (sorry for the other changes visible – the actual change in behaviour is only for the status bar):

huftis edited the summary of this revision. (Show Details)May 30 2018, 5:11 PM
huftis added a reviewer: Localization.
huftis added a project: Localization.
huftis added a subscriber: Localization.

Note that I’ve tried making a similar change for the numeric columns in the table in the project view, but this broke sorting (and I don’t know how to fix it), so it’s not included in this patch.

huftis edited the summary of this revision. (Show Details)May 30 2018, 5:32 PM
huftis edited the test plan for this revision. (Show Details)
aacid added a subscriber: ilic.May 30 2018, 10:30 PM

I'm not too thrilled about this to be honest, seems that this is something i18n should be doing by default, pinging @ilic to see what he would think about fixing/expanding ki18n to do "the right thing" by default

I'm not too thrilled about this to be honest, seems that this is something i18n should be doing by default […]

Hmm, you wouldn’t want to format *all* number-like strings. For example, the year 2018 shouldn’t be displayed as ‘2,018’ in English …

aacid added a comment.Jun 3 2018, 4:59 PM

But 2018 is not a number, it's a year ;)

the question is, what should be the default having them localized or not? And of course you should have the option to manually have both

aacid added a comment.Jun 3 2018, 9:07 PM

I personally don't think that makes any sense, why would the translator be the one to decide?

I personally don't think that makes any sense, why would the translator be the one to decide?

Maybe this is true for i18n, but false for QString::arg in general.

I think we need translator ideas here, as you mentioned.

huftis added a comment.EditedJun 15 2018, 5:17 PM

I'm not too thrilled about this to be honest, seems that this is something i18n should be doing by default, pinging @ilic to see what he would think about fixing/expanding ki18n to do "the right thing" by default

Apparently, calling i18nc() used to format the numbers according to the locale/language:

https://bugs.kde.org/show_bug.cgi?id=167915
https://bugs.kde.org/show_bug.cgi?id=168134 (especially the discussion in this one)

And I (now) agree that it makes sense to do so. See also https://bugs.kde.org/show_bug.cgi?id=395392, which would be fixed by having i18nc() format numbers according to the user’s locale (or preferably by the language of the string).

I’m actually not sure how KDE’s i18n stuff is actually supposed to work now. The official(?) tutorial at https://techbase.kde.org/Development/Tutorials/Localization/i18n seems severely outdated (e.g., it talks a lot about KLocale stuff).

I’m actually not sure how KDE’s i18n stuff is actually supposed to work now. The official(?) tutorial at https://techbase.kde.org/Development/Tutorials/Localization/i18n seems severely outdated (e.g., it talks a lot about KLocale stuff).

https://api.kde.org/frameworks/ki18n/html/index.html references the programmer's guide:
https://api.kde.org/frameworks/ki18n/html/prg_guide.html

According to this,

Integer arguments will be by default formatted as if they denote an amount, according to locale rules (thousands separation, etc.)

So shouldn’t the original code, for example

statusBarItems.insert(ID_STATUS_TOTAL, i18nc("@info:status message entries","Total: %1", total));

work (i.e. be formatted using a thousands separator)?

In https://git.reviewboard.kde.org/r/127800/, @ilic wrote:

To have localized numbers is the expected behavior (and documented as such). But it was "temporarily" disabled between kdelibs and KF5, until replacements for KLocale were decided.

So I guess it’s just (still) a bug that i18n() and friends don’t localize the numbers.

This comment was removed by huftis.
huftis updated this revision to Diff 37935.Jul 17 2018, 8:23 AM

Rebasing on Applications/18.08

huftis edited the summary of this revision. (Show Details)Jul 17 2018, 8:24 AM

Adding @kossebau since he had at some point of history a patch for fixing this at the ki18n level. Friedrich can you comment on it?

Since this turned already into a discussion, shall we use %Lx version for KF5 libraries using Qt's translation system? I mean in the source text.

+1

QLocale().toString is the only thing that currently works. No other ways, like the recommended [1] ki18n*() with subs() or another formatting, do work.

[1] https://techbase.kde.org/Development/Tutorials/Localization/i18n_Krazy

aacid added a comment.Dec 16 2018, 6:31 PM

I still object to this being merged, the actual problem has to be fixed, not workarounded in every single app.

Human's life is short. Can we have a "grace" period (say 3 years)?

Should the big good fixes were not landed in 3 years since the problem recognized, we can apply our small dirty hacks.

Since this turned already into a discussion, shall we use %Lx version for KF5 libraries using Qt's translation system? I mean in the source text.

I’ve just tested this, but changing %1 to %L1 doesn’t seem work; the %L1 is displayed verbatim.

BTW, I see other parts of KDE libraries do use the QLocale() solution. For example kio uses it for formatting the ‘Size:’ property (file size in bytes) shown when you right-click on a file and select ‘Properties’: https://cgit.kde.org/kio.git/tree/src/widgets/kpropertiesdialog.cpp#n1087
But I guess that’s just because i18n() and friends don’t actually work the way they’re supposed to work.

I’ve just tested this, but changing %1 to %L1 doesn’t seem work; the %L1 is displayed verbatim.

Did you test it with Qt's system, or KI18n? I meant to use it with tr() (KF5 Tier 1 libraries that uses Qt localization system, like KI18n).

huftis added a comment.EditedSep 1 2019, 5:19 PM

I’ve just tested this, but changing %1 to %L1 doesn’t seem work; the %L1 is displayed verbatim.

Did you test it with Qt's system, or KI18n? I meant to use it with tr() (KF5 Tier 1 libraries that uses Qt localization system, like KI18n).

I only tested it with i18n(). Changing

statusBarItems.insert(ID_STATUS_TOTAL, i18nc("@info:status message entries", "Total: %1", total));

in src/project/projecttab.cpp into

statusBarItems.insert(ID_STATUS_TOTAL, tr("Total: %L1", "@info:status message entries").arg(total));

does work – sort of. That is, the number is displayed using my locale setting (123456 is displayed as 123 456). However, the translation of the string isn’t used (so the string is displayed as Total: 123 456 instead of TranslationOfTotalString: 123 456). (I did update %1 to %L1 in the .po/.mo file.)

aacid added a comment.Sep 4 2019, 8:33 PM

Should this be cancelled given this should be fixed on the latest ki18n?

huftis abandoned this revision.Sep 5 2019, 5:31 PM

Should this be cancelled given this should be fixed on the latest ki18n?

Indeed. I can confirm that with the latest ki18n, the numbers on the status bar are correctly formatted.