kformat: Make it possible to properly translate relative days of the week
ClosedPublic

Authored by mpyne on Jan 8 2017, 5:09 PM.

Details

Summary

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.

See also Bug 335106.

Test Plan

Change builds and installs properly, and all kcoreaddons tests continue to pass (with the kformattest autotest revised per this change).

Diff Detail

Repository
R244 KCoreAddons
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
mpyne updated this revision to Diff 9867.Jan 8 2017, 5:09 PM
mpyne retitled this revision from to kformat: Make it possible to properly translate relative days of the week.
mpyne updated this object.
mpyne edited the test plan for this revision. (Show Details)
mpyne set the repository for this revision to R244 KCoreAddons.
Restricted Application added a project: Frameworks. · View Herald TranscriptJan 8 2017, 5:09 PM
aspotashev added inline comments.Jan 8 2017, 7:04 PM
src/lib/util/kformatprivate.cpp
381

Needs a space: "switch ("

382

Indentation of "case " lines is probably against the coding style.

400

http://doc.qt.io/qt-5/qdate.html#dayOfWeek says "Returns 0 if the date is invalid". What happens when the input date is invalid?

mpyne updated this revision to Diff 9950.Jan 9 2017, 11:46 PM

Update the diff to match coding style and explicitly handle the case of an invalid date. Added a unit test for the invalid date handling.

Testsuite continues to pass.

aacid requested changes to this revision.Jan 12 2017, 11:12 PM
aacid added a reviewer: aacid.
aacid added a subscriber: aacid.

I find the comments misleading (maybe because i'm not english native) but

if (daysTo < -1) {
      switch (date.dayOfWeek()) {
      case 1:
          return tr("Last Monday",    "day in the previous week");
      case 2:

Why does it have to be the previous week? If today is Wednesday and the date we're referring to is Monday, daysTo will be -2 and it will still be the current week and not the previous, no?

else if (daysTo > 1) {

switch (date.dayOfWeek()) {
case 4:
    return tr("Next Thursday",  "day in the week after this");

If today is Monday and the date we're referring to is Thursday, daysTo will be 3 and it's not "the week after this" it's "this week".

Or am i understanding something wrong?

This revision now requires changes to proceed.Jan 12 2017, 11:12 PM
mpyne added a comment.Jan 13 2017, 2:15 AM
In D4023#76891, @aacid wrote:

I find the comments misleading (maybe because i'm not english native) but

if (daysTo < -1) {
      switch (date.dayOfWeek()) {
      case 1:
          return tr("Last Monday",    "day in the previous week");
      case 2:

Why does it have to be the previous week? If today is Wednesday and the date we're referring to is Monday, daysTo will be -2 and it will still be the current week and not the previous, no?

else if (daysTo > 1) {

switch (date.dayOfWeek()) {
case 4:
    return tr("Next Thursday",  "day in the week after this");

If today is Monday and the date we're referring to is Thursday, daysTo will be 3 and it's not "the week after this" it's "this week".

Or am i understanding something wrong?

You're right. What's a better phrasing? Or, is the context even necessary for translators here?

Maybe something like "the most recent such day before today" and "the next such day after today"?

In D4023#76899, @mpyne wrote:
In D4023#76891, @aacid wrote:

I find the comments misleading (maybe because i'm not english native) but

if (daysTo < -1) {
      switch (date.dayOfWeek()) {
      case 1:
          return tr("Last Monday",    "day in the previous week");
      case 2:

Why does it have to be the previous week? If today is Wednesday and the date we're referring to is Monday, daysTo will be -2 and it will still be the current week and not the previous, no?

else if (daysTo > 1) {

switch (date.dayOfWeek()) {
case 4:
    return tr("Next Thursday",  "day in the week after this");

If today is Monday and the date we're referring to is Thursday, daysTo will be 3 and it's not "the week after this" it's "this week".

Or am i understanding something wrong?

You're right. What's a better phrasing? Or, is the context even necessary for translators here?

I'd say let's go with context, or maybe even better english (or more codepaths?)

Can you as a native speaker confirm this theory i've heard?

If we are on "Monday 16", "Next Wednesday" means "Wednesday 25" if you want "Wednesday 18" you should say "This Wednesday"

Maybe something like "the most recent such day before today" and "the next such day after today"?

mpyne added a comment.Jan 15 2017, 2:40 PM
In D4023#77304, @aacid wrote:

Can you as a native speaker confirm this theory i've heard?

If we are on "Monday 16", "Next Wednesday" means "Wednesday 25" if you want "Wednesday 18" you should say "This Wednesday"

Yes, if you are on a Monday the 16th, the immediate next Wednesday (18th) would generally be referred to as "this Wednesday" while the Wednesday following (25th) would be "next Wednesday".

This might not be true for all English dialects though. E.g. en_GB seems to have the immediately following Wednesday (18th) as "Wednesday next", while the Wednesday after (25th) would "Wednesday week".

However if the number of days between now and then is long enough then many people would still refer to the later date as "next" instead of "this". This is reflected in some other APIs. For instance I tried adding a new calendar entry to a Google-based account for "next Thursday" from today (Sunday) and it added it for 4 days from now instead of 11 days from now. However even when adding an entry for "next Monday" (i.e. tomorrow or 8 days from now), Google still chose tomorrow.

As long as our behavior in the code is consistent there shouldn't be much problem with using "Next $day" even in en_US since we're used to computer outputs not being precisely reflective of natural speech, and even in the U.S. there are people who always use "Next $day" in their natural speech to refer to the immediately succeeding day.

As a result, I would keep the current scheme (at least for en_US) since that way there's less "magic" needed for the user in trying to decode what date the computer is trying to refer to.

aacid accepted this revision.Jan 15 2017, 6:12 PM
aacid edited edge metadata.

ok, then let's go with

Maybe something like "the most recent such day before today" and "the next such day after today"?

i guess

This revision is now accepted and ready to land.Jan 15 2017, 6:12 PM
aspotashev accepted this revision.Jan 15 2017, 9:13 PM
aspotashev edited edge metadata.
This revision was automatically updated to reflect the committed changes.