Bug 335106 - Word puzzle: "Next %1" does not differentiate by grammatical genders of %1 (day of week)
Summary: Word puzzle: "Next %1" does not differentiate by grammatical genders of %1 (d...
Status: RESOLVED FIXED
Alias: None
Product: frameworks-kcoreaddons
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: 4.99.0
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Michael Pyne
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-20 23:16 UTC by Alexander Potashev
Modified: 2017-01-17 01:49 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.31


Attachments
Splits next/last day strings into a different context for each day of the week (4.87 KB, text/plain)
2014-05-23 15:45 UTC, Michael Pyne
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Potashev 2014-05-20 23:16:34 UTC
Look at this string, same problem applies to the similar "Last %1" string:
    #. a day of the week, eg "Monday" (but translated). Refers to the soonest such day that has not already happened.
    #: lib/util/kformatprivate.cpp:389
    #, qt-format
    msgctxt "KFormat|"
    msgid "Next %1"

"%1" here is a placeholder for day of week (Monday, etc). I cannot translate this into Russian properly because the adjectives in Russian have genders and follow the gender of the noun it belongs to. So does the adjective "next" here - it should follow the grammatical gender of the particular day of week. But the form of translation of "next" cannot be changed because there is only one translatable string.

With KI18n one could differentiate translations by genders/etc of %1 using translation scripting (Transcript), but the Qt translation system does not provide any similarly powerful features.

Reproducible: Always
Comment 1 Michael Pyne 2014-05-22 00:32:44 UTC
Chusslove, any advice for me on this? Is there an equivalent to Transcript with Qt5?
Comment 2 Chusslove Illich 2014-05-22 08:47:59 UTC
Nah, no such thing. Not possible to unpuzzle, since day names come from outside kcoreaddons. Must go for "least bad" translation.
Comment 3 Chusslove Illich 2014-05-22 09:48:41 UTC
Well... on the other hand, duplicating seven day name translations times two messages might not be too bad solution :)
Comment 4 Michael Pyne 2014-05-23 00:27:38 UTC
(In reply to comment #3)
> Well... on the other hand, duplicating seven day name translations times two
> messages might not be too bad solution :)

Perhaps, but it sounds like there would still need to be some way to decide which gendered day name translation to use, which we can't figure out from the KFormat API alone, as in this case the API simply passes a date or date-time and a "long" or "short" format type to return a translated relative date.
Comment 5 Alexander Potashev 2014-05-23 00:44:52 UTC
Hi Michael,
Excuse me, I did not get your point. KFormatPrivate::formatRelativeDate() gets enough information to decide what should be translated.
The code is going to look like this:
switch (date.dayOfWeek()) {
case Qt::Monday:
    return tr("Next %1", "for Monday");
case Qt::Tuesday:
    return tr("Next %1", "for Tuesday");
[...]
}
Comment 6 Alexander Potashev 2014-05-23 00:45:43 UTC
Forgot to add .arg(...), but I guess the coding idea was already clear.
Comment 7 Michael Pyne 2014-05-23 15:13:14 UTC
Sorry, I thought you meant it was necessary to know the gender of other words in the sentence, not of the day itself. If this can be done just by using a different i18n string for each day of the week then that would be simple enough.
Comment 8 Michael Pyne 2014-05-23 15:45:24 UTC
Created attachment 86789 [details]
Splits next/last day strings into a different context for each day of the week

Would something like this work in order to allow these strings to be properly translated? The tests still pass, code still builds with this patch.
Comment 9 Michael Pyne 2014-08-08 21:21:52 UTC
Ping? I'd like to know if this is workable for the translators before I commit. Is this still an issue?
Comment 10 Alexander Potashev 2014-08-09 11:24:11 UTC
Sorry for late response. The patch you have suggested makes things better, but I've just realized we need no "%1" in those messages, i.e. "Last %1"/"where day is Monday") can be changed to "Last Monday" which would be
 1. Easier for translators to get the sense for this message.
 2. Add more flexibility as you can put "Monday" in the necessary form (if needed) in this particular message. For example, in Russian the week day names are not capitalized, e.g. "Monday" is "понедельник", not "Понедельник". And I'm afraid dayName() might return a capitalized name.
Comment 11 Alexander Potashev 2015-06-25 12:28:29 UTC
Ping. Shall I do a review request myself?
Comment 12 Alexander Potashev 2015-07-02 22:26:36 UTC
Oops, tr("Last Monday") won't work as expected when format == ShortFormat. The output "Last Mon" is expected in this case, and thus the autotests break.

I don't see no reason for showing a string like "Last Mon" in the UI, but we probably can't break the API by changing "Last Mon" to "Last Monday".
Comment 13 Michael Pyne 2017-01-17 01:49:58 UTC
Git commit aeff11101f8513209f52aabfa72ee8b9349b915f by Michael Pyne.
Committed on 17/01/2017 at 01:45.
Pushed by mpyne into branch 'master'.

kformat: Make it possible to properly translate relative dates.

KFormat::formatRelativeDate allows one to obtain a human-readable date like
"Last Wednesday" or "Next Thursday" for dates within a week of the current
date.

The returned string cannot be properly translated in all languages since it's
generated using a placeholder of the form "Next %1" -- the word Next (or Last)
may itself need to be modified to be correct which can't be done with the
current translation system.

The fix is just to return "Next $dayName" directly, based on the day name as
appropriate, and allow the translators to translate the entire phrase.

The auto tests are adjusted as well. They were actually incorrect before this
change, since the API documentation for formatRelativeDate makes clear that the
date format is only applied if the date is *not* within a week of the current
date.
FIXED-IN:5.31

Differential Revision: https://phabricator.kde.org/D4023

M  +10   -4    autotests/kformattest.cpp
M  +38   -10   src/lib/util/kformatprivate.cpp

https://commits.kde.org/kcoreaddons/aeff11101f8513209f52aabfa72ee8b9349b915f