Ckan: Capitalized months in "localized nice dates" (French)

Created on 6 May 2020  路  4Comments  路  Source: ckan/ckan

CKAN 2.8.4

Please describe the expected behaviour

The function localised_nice_date() is used to display "localized nice timestamps", with or without the hour. In places where a "localized nice date" is displayed, month names should be fully lowercase in French. For example, January 1, 2020 should be "1 janvier 2020".

Please describe the actual behaviour

The first letter of the month name is uppercase. To take the same example as above (January 1, 2020), it is "1 Janvier 2020" in French.

What steps can be taken to reproduce the issue?

  1. Go to a resource page (for example https://demo.ckan.org/fr/dataset/aass/resource/a575cdb5-079f-4665-a82d-dbb79d9fc14a, but this issue cannot be demonstrated on demo.ckan.org currently)
  2. Check the Created field

This unfortunately cannot be solved simply by modifying translations. The strings are generated as follows:

    if with_hours:
        return (
            # NOTE: This is for translating dates like `April 24, 2013, 10:45 (Europe/Zurich)`
            _('{month} {day}, {year}, {hour:02}:{min:02} ({timezone})') \
            .format(**details))
    else:
        return (
            # NOTE: This is for translating dates like `April 24, 2013`
            _('{month} {day}, {year}').format(**details))

Python's format language unfortunately does not allow lowercasing a variable (a proposal to allow that was rejected).

To solve this, _details['month']_ needs to contain the month with the proper case, sometimes capitalized, sometimes not, depending on the language. I guess strftime("%B") returns that, but I am not sure the case is correct.

Most helpful comment

maybe we can delete some code in ckan/lib/formatters.py and rely on babel for more of our date formatting

All 4 comments

maybe we can delete some code in ckan/lib/formatters.py and rely on babel for more of our date formatting

strftime() does offer "turnkey" solutions like %c. I do not see any which corresponds exactly to the current format at first sight though.
The ICU project offers very advanced features which I am confident could satisfy this need, I do not know about babel though.

As CKAN is already using flask-babel, I like the idea of using babel's capabilities. Actually, i was sure that we already relying on it. @Chealer , here are few examples of usage.
just plaint invocation of flask_babel.format_datetime returns May 7, 2020, 11:49:45 PM when locale is en and 7 mai 2020 脿 23:49:30 for fr , so it should satisfy basic needs. And we can pass additional options, like required formats.
The only thing I don't like - currently we are displaying dates in the same format for any locale. With babel, each locale will show dates in a different form. It fixes the original issue, but someone will complain that format has changed. We cannot make everyone happy, neither we should support two different ways of formatting dates. But maybe you have any ideas, how to reduce user's dissatisfaction?

That looks perfect, thank you Sergey.

Regarding change, currently French and English are the same because there was an error in the translation (the French was left identical to the English format), but I fixed it and that is already scheduled to change for the next version. And it had already changed between 2.4.1 and 2.8.3. So there is already frequent change there. More change should not be problematic as long as it is in the right direction, but if issues are reported, we can deal with them, possibly offering configuration. I just checked with a CMS, and it offers no less than 8 fields to configure dates/times display. There may be requests to control display of the timezone specifier, which is currently displayed in the _with_hours_ case (it wasn't in 2.4.1).

Was this page helpful?
0 / 5 - 0 ratings