Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format day of month ('Do') french translation error #437

Closed
peterpeterparker opened this issue Feb 15, 2017 · 13 comments
Closed

Format day of month ('Do') french translation error #437

peterpeterparker opened this issue Feb 15, 2017 · 13 comments

Comments

@peterpeterparker
Copy link

peterpeterparker commented Feb 15, 2017

Hi,

I think that the format of the day of month ('Do') isn't correct in french, it doesn't follow the same rules as in english or german for example or even doesn't follow the same logic as day of the year of week in french.

day of month ('Do'):

1st, 2nd, ..., 31st in english is correct
or
1., 2., ... 31. in german is correct too

but for day of the month in french, you not gonna says
1er, 2e, ... 31e

but

1er, 2, ... 31

like "le 1er janvier 2017" but like "le 2 janvier 2017", ... "le 31 janvier 2017"

Therefore I think that the function ordinal in src/locale/fr/build_format_locale/index.js should be extended, when the number is greater than 1, the code "number + 'e'" should only apply for day of the week and day of the year where it should only return "number" when day of the month.

Best regards

@kossnocorp
Copy link
Member

Thank you for the report! cc @date-fns/i18n-french

@fbonzon
Copy link
Contributor

fbonzon commented Feb 23, 2017

I'm trying to fix the exact same problem in Moment.js. (And might fix it here too.) Please read related issue moment/moment#3375 (comment)

The Do token is correctly implemented here, in my understanding. It's a question of definition and documentation. The definition of Do is "day of month with ordinal suffix". Example usage:

English

2017-03-01 → Do day of the month → 1st day of the month
2017-03-23 → Do day of the month → 23rd day of the month
2017-03-24 → Do day of the month → 24th day of the month

French

2017-03-01 → Do jour du mois → 1er jour du mois
2017-03-23 → Do jour du mois → 23e jour du mois
2017-03-24 → Do jour du mois → 24e jour du mois

When writing long date format in French, we want to use ordinal for day 1 (token Do) and cardinal for other days (token D). There is currently no way to express this in the locale files.

Solutions I can think of:

  1. Create a new token with definition "day of month for long date format (with cardinal or ordinal depending on locale)". For French, it would return the same value as Do for day 1, and same value as D otherwise.

Name it Dom for Day of month (latest suggestion in the above referred issue). Or F (next letter after D, and E is already taken) ? Or LD for "Localized Day of month" ?

Or maybe this problem is too specific of the French language, doesn't merit a dedicated token for all languages, and is semantically better handled within the French locale code. This brings second solution:

  1. Implement the equivalent of L, LL, LLL, LLLL formats in Moment.js. Make the format depend on the date, and return in French, e.g. for LL:
    Do MMMM YYYY when day = 1
    D MMMM YYYY otherwise

Other ideas? What is your preference?

@leshakoss
Copy link
Contributor

leshakoss commented Feb 23, 2017

var monthsTokens = ['MMM', 'MMMM']
monthsTokens.forEach(function (monthToken) {
  formatters['Do ' + monthToken] = function (date) {
    var dayOfMonth = date.getUTCDate()

    var formattedDayOfMonth = dayOfMonth === 1 ? '1er' : String(dayOfMonth)
    var formattedMonth = formatters[monthToken](date)

    return formattedDayOfMonth + ' ' + formattedMonth
  }
})

Maybe something like that? (haven't tested it) It makes formatters 'Do MMM' and 'Do MMMM'. We did the similar thing in Russian locale: https://github.com/date-fns/date-fns/blob/master/src/locale/ru/build_format_locale/index.js#L75

@leshakoss
Copy link
Contributor

@fbonzon oh yeah, I missed your pull request, sorry 😅

@peterpeterparker
Copy link
Author

I'm agree with your comment @fbonzon

Maybe other languages, like Italian, follow the same rules? Like "Il 1° guigno" ("the 1th june") but "Il 2 guigno" ("the 2nd june").

About your ideas of solution 1. or 2., I personally think both achieve the goals and can't tell wich one is the better ;)

@fbonzon
Copy link
Contributor

fbonzon commented Feb 23, 2017

@leshakoss #448 addresses an unrelated problem, thus I did not mention it here.

A similar code to the Russian example you mentioned could be written for French, yes.

If I understand correctly, it is possible to include a given token in several formatters? How is selected the one to use? E.g. if I define formatters for
MMM
Do MMM
How is MMM formatted? With the second one because is longer token? Or the order of formatters definitions is relevant, and the first (or last one) matching is selected?

@leshakoss
Copy link
Contributor

@fbonzon both formatters (MMM and Do MMM) should work, I think

@fbonzon
Copy link
Contributor

fbonzon commented Feb 23, 2017

Yes, but what is the logic to decide which formatter to use? I could dig into the code, but maybe you know the answer already.

Provided I define formatters for (1) MMM, (2) Do and (3) Do MMM, there is an ambiguity for the formatter to use to display Do and MMM when they appear in format strings. Which formatter has priority?

@leshakoss
Copy link
Contributor

leshakoss commented Feb 23, 2017

@fbonzon alright

token string is splitted by a regexp of all possible tokens, sorted backwards alphanumerically:
https://github.com/date-fns/date-fns/blob/master/src/locale/_lib/build_formatting_tokens_reg_exp/index.js#L20
So, regexp would prefer first ^MMM, then ^Do MMM, then ^Do. At least, that's how it works in Russian locale:

> format(new Date(), 'MMMM Do Do MMMM Do', {locale: ruLocale})
'февраль 23-е 23-е февраля 23-е'

Here, it splitted the token string like this: ['MMMM', ' ', 'Do', ' ', 'Do MMMM', ' ', 'Do']

@fbonzon
Copy link
Contributor

fbonzon commented Feb 23, 2017

Is now clear to me, thanks. Verified in code, is the same for all locales. The priority is indeed defined only by reversed alphabetical order.

It would work for our use case. We would modify contents of Do MMM and Do MMMM, by omitting the ordinal suffix for days other than 1.

I can code this is it's your preferred solution. It's not the most elegant one, in my opinion, but it works.

@leshakoss
Copy link
Contributor

@fbonzon yeah alright thank you 😄

@fbonzon
Copy link
Contributor

fbonzon commented Feb 27, 2017

Fix released in v1.28.0

@fbonzon fbonzon closed this as completed Feb 27, 2017
@antoinerousseau
Copy link

antoinerousseau commented Nov 3, 2020

Could we get a similar fix in v2? (see #1391 (comment))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants