Closed sikmir closed 3 years ago
@sikmir
I also find something like this when translate to Chinese, for my case, I added a special case
So, strftime('%B')
returns a wrong string when using the ru_RU.UTF-8
locale?
So,
strftime('%B')
returns a wrong string when using theru_RU.UTF-8
locale?
Yes, the reason is that strftime
knows nothing about grammatical cases. Month name substituted by %B
is correct in such context as strftime('%d %B')
(01 сентября
), but that is wrong in case of strftime('%B')
(сентябрь
is expected).
I guess, I will add a localization.py
file with locale-aware functions that return month & day names, e.g. something like
def localized_month_name(locale_name: str, date: datetime.date) -> str:
# special case for russian
if locale_name == "ru_RU":
return ...
# default
return date.strftime("%B")
def localized_day_of_week_name(locale_name: str, day_of_week: int, short: bool) -> str:
# special case for chinese
if locale_name == "zh_CN":
...
return ...
# default case
...
return ...
Would that work?
I think so.
What about adding util function with all month names and maintaining their proper translations for us without relying on strftime
?
@sikmir for now, I've added localization.py
with functions localized_day_of_week_name
and localized_month_name
that use the day/month names of the current locale by default. If a language (like Russian) requires some special treatment, the functions can be adapted accordingly; I've already done this for Chinese short day names.
You can now extend localized_month_name
with the special cases for Russian.
That treatment is not like for Chinese short day names, here we have no proper translations, so we need something like https://github.com/django/django/blob/master/django/utils/dates.py#L13-L17
@sikmir I've just added explicit month translations (with initial translations based on strftime('%B')
).
I would be great if you could fix the Russian translation file (locale/ru_RU/LC_MESSAGES/gpxposter.po
) such that the month names are correct.
Month names are printed in the nominative case for all languages except Russian, where it should be
январь
instead ofянваря
in the example bellow, compare:--language de_DE
:--language en_US
:--language fi_FI
:--language fr_FR
:--language ru_RU
:That's caused by: https://github.com/flopp/GpxTrackPoster/blob/2a405da9dbdb153c584beed055fd84879724a075/gpxtrackposter/calendar_drawer.py#L105 Let's check it: