Fix context for QDateTime::toString() translations
ClosedPublic

Authored by elvisangelaccio on Feb 5 2019, 9:10 PM.

Details

Summary

The documentation of QDateTime::toString() says that:

Any sequence of characters that are enclosed in single
quotes will be treated as text and not be used as an expression.

This means that translators cannot replace single quotes with other
characters such as «...». This is now described in the context of the
affected strings.

We also check that the translated string contains exactly 2 single
quotes, and we use the untraslated string otherwise.

BUG: 401382

Diff Detail

Repository
R318 Dolphin
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 8406
Build 8424: arc lint + arc unit
elvisangelaccio created this revision.Feb 5 2019, 9:10 PM
Restricted Application added a project: Dolphin. · View Herald TranscriptFeb 5 2019, 9:10 PM
Restricted Application added a subscriber: kfm-devel. · View Herald Transcript
elvisangelaccio requested review of this revision.Feb 5 2019, 9:10 PM
aacid added a subscriber: ltoscano.Feb 5 2019, 9:57 PM

One thing we could do is not pass the string directly to toString and check if there's any ' character (there should be at least/exactly 2) if not ignore the translation and go with untranslated, that will be better than "random stuff", but i guess this is probably enough.

@ltoscano what do you think?

If it's not too difficult to pre-filter the string, maybe it's worth doing.

  • Use untraslated string as fallback
elvisangelaccio edited the summary of this revision. (Show Details)Feb 10 2019, 9:42 PM

Can you add a qWarning in the else branches saying something "the translation is wrong, file a bug report"?

  • Added warnings

I didn't realize you moved the text out of the i18n call.

If you do that gettext won't extract it and thus it'll be untranslatable.

I see that you did that so you can reuse it untranslated later.

Maybe this would work (haven't tried it)?

KLocalizedString s = ki18nc(context, text);
const QString translatedFormat = s.toString();
if (translatedFormat.count(QLatin1Char('\'')) == 2) { /* good */ }
else { qCWarning();      newGroupValue = s.toString({"en"}); }

i think that would mean "no" translation in the else since it is asking for an en translation.

I didn't realize you moved the text out of the i18n call.

If you do that gettext won't extract it and thus it'll be untranslatable.

I see that you did that so you can reuse it untranslated later.

Maybe this would work (haven't tried it)?

KLocalizedString s = ki18nc(context, text);
const QString translatedFormat = s.toString();
if (translatedFormat.count(QLatin1Char('\'')) == 2) { /* good */ }
else { qCWarning();      newGroupValue = s.toString({"en"}); }

i think that would mean "no" translation in the else since it is asking for an en translation.

Ah sorry, didn't know that. I'll try.

  • Use KLocalizedString
aacid added inline comments.Feb 17 2019, 6:01 PM
src/kitemviews/kfileitemmodel.cpp
2059

Sorry for being the most nitpicky person ever, should we include translatedFormat here (and the rest of the warning messages)?

Seems like it could be useful

Improved warnings

Code looks good to me, do you want me to actually test it or are you confident enough that it works?

@aacid If the french translation is still broken, maybe would be good to test this patch using a french locale?

Hmmmm, it doesn't seem to totally work

I get this https://i.imgur.com/bM3IPeu.png

I guess the MMMM and yyyy should have been replaced by actual text, right?

Hmmmm, it doesn't seem to totally work

I get this https://i.imgur.com/bM3IPeu.png

I guess the MMMM and yyyy should have been replaced by actual text, right?

Yeah. Did you get the qWarning in the else branch? How do I reproduce that?

Hmmmm, it doesn't seem to totally work

I get this https://i.imgur.com/bM3IPeu.png

I guess the MMMM and yyyy should have been replaced by actual text, right?

Yeah. Did you get the qWarning in the else branch? How do I reproduce that?

Well, you need to be running in a localized language and then break your translation.

Here is a broken .mo for dolphin (in french)

install it to /usr/share/locale/fr/LC_MESSAGES/dolphin.mo and if you have the french locale running it with LANG=fr_FR.UTF-8 dolphin should give you the broken behaviour, if you don't have the fr locale setup just copy it to the italian folder :D

Call QDateTime::toString() also in the untranslated case

Here is a broken .mo for dolphin (in french)

install it to /usr/share/locale/fr/LC_MESSAGES/dolphin.mo and if you have the french locale running it with LANG=fr_FR.UTF-8 dolphin should give you the broken behaviour, if you don't have the fr locale setup just copy it to the italian folder :D

Thanks, I was able to reproduce it using this file. I forgot to call QDateTime::toString() also when we go with the untranslated string...

aacid accepted this revision.Mar 5 2019, 12:02 AM

Looks good to me :)

This revision is now accepted and ready to land.Mar 5 2019, 12:02 AM
This revision was automatically updated to reflect the committed changes.