make units and prefixes of formatValue translatable
ClosedPublic

Authored by astippich on Sep 29 2018, 9:26 AM.

Details

Summary

give the possibility to translate the prefix und unit strings

Diff Detail

Repository
R244 KCoreAddons
Branch
translate_units
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 3582
Build 3600: arc lint + arc unit
astippich created this revision.Sep 29 2018, 9:26 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptSep 29 2018, 9:26 AM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
astippich requested review of this revision.Sep 29 2018, 9:26 AM

@bruns please have a look at the changes. In particular, regarding "µ" and windows support. I don't know if this will be able to compile on windows, or how to fix it for tr() function.
@safaalfulaij please verify if this fixes the RTL issue for you

Since the joining between number and format is translatable, that's great. I meant that if it is kept untranslatable, problems regarding RTL will happen.

src/lib/util/kformatprivate.cpp
116–132

Line 160:

} else {
    value /= entry->binaryFactor;
    prefixString = QString(entry->prefixChar).toUpper();

How this is “Metric”?

168–170

And what about this? It should never be a puzzle string by the way.

Since the joining between number and format is translatable, that's great. I meant that if it is kept untranslatable, problems regarding RTL will happen.

Sorry, I don't understand clearly, will this patch (once all issues are fixed) solve your problem or not?

src/lib/util/kformatprivate.cpp
116–132

The prefixes for the IEC binary prefixes (for e.g. 2^10) are made up by the SI prefixes plus an "i", see below. But it actually is an SI prefix, to be more precise.

168–170

Overlooked that one. Must this then be something like tr("1%2%).arg(... ...)?

I came into anther problem, this time with the unit selection.
In Arabic, we don't put a dot between the prefix and the unit if we're talking about meters (mm, cm, km), but we do with other units (k.Byte, M.Byte, G.Byte).

If ki18n was used here, all of this can be locale-specific, but unfortunately that's not the case. I think I understand now why there are many strings for all of this unit stuff.

src/lib/util/kformatprivate.cpp
168–170

Well, I searched other languages and no one seems to do as Arabic does. We do not abbreviate in this case and just write the whole "Mebi.Byte" ("Byte" is always written, "M.Byte" > "MB").
And of course, there is no one solid naming of the units, so adding just one letter will not get the right meaning. Adding another dot will make things more crowded -> "M.i.Byte" (This is fine in English, but in Arabic it is really ugly and means nothing.)

astippich updated this revision to Diff 42563.Sep 29 2018, 4:34 PM
  • change description for prefixes and make the IEC prefix translatable
astippich added inline comments.Sep 29 2018, 4:39 PM
src/lib/util/kformatprivate.cpp
168–170

I uploaded a new version, but with what you describe, this will not suffice to fulfill your needs for IEC binary prefixes (please confirm). For the record, I haven't seen it anywhere in English that dots are put in between.
I guess a second map with the IEC binary prefixes is required so that one can translate them separately.

I'm away for the next week, so will continue to work on the patch afterwards.

astippich updated this revision to Diff 43034.Oct 7 2018, 1:24 PM
  • add seperate, translatable string for IEC binary prefixes
safaalfulaij accepted this revision.Oct 7 2018, 1:40 PM

Thanks!
I think this solved all my issues. I can for meter unit change the formatting so that tr("%1 %2", "no Prefix") is translated to "%1%2" and choose to keep the dot or remove it in the unitStrings translation. ("bit" -> ".bit", "m" -> "m")
By the way, shouldn't that also be the case for English? I don't see people write "1 m" but "1m", "200 B" but "200B", same for Hz, not sure about bits. The space is not there when abbreviation is used.

This revision is now accepted and ready to land.Oct 7 2018, 1:40 PM
safaalfulaij added inline comments.Oct 7 2018, 1:44 PM
src/lib/util/kformatprivate.cpp
124

Space before }?

125

Space before }?

127

Extra space after }?

Thanks!
I think this solved all my issues. I can for meter unit change the formatting so that tr("%1 %2", "no Prefix") is translated to "%1%2" and choose to keep the dot or remove it in the unitStrings translation. ("bit" -> ".bit", "m" -> "m")
By the way, shouldn't that also be the case for English? I don't see people write "1 m" but "1m", "200 B" but "200B", same for Hz, not sure about bits. The space is not there when abbreviation is used.

Great! Now looking forward to feedback from @bruns regarding the implementation :)
Scientifically it is correct to put a (small) space between value and unit.

astippich updated this revision to Diff 43038.Oct 7 2018, 1:50 PM
  • fixup spaces

If no-one objects or has any comments regarding coding, I'm going to land this revision in one week

This revision was automatically updated to reflect the committed changes.