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

Overwrite `LocaleBorg.get_month_name` for custom locale? #2029

Closed
felixfontein opened this Issue Sep 6, 2015 · 8 comments

Comments

Projects
None yet
4 participants
@felixfontein
Contributor

felixfontein commented Sep 6, 2015

When trying to use Nikola for a custom locale which Python doesn't know (say, for a phantasy language or for some local dialect), one can fix most translations by translating messages_en.py. Unfortunately, fixing the month names for the archives is not possible (AFAIK), because they are generated by LocaleBorg.get_month_name, which uses Python functions which don't know about the custom locale.
How should it be possible to fix this? How about being able to specify the month name translations in messages_XXX.py? Or is this already somehow possible with some Python magic?

@Kwpolska

This comment has been minimized.

Show comment
Hide comment
@Kwpolska

Kwpolska Sep 6, 2015

Member

You would have to modify the calendar module pretty heavily. We rely on the operating system for locales, and I doubt we will be able to/willing to change that.

Member

Kwpolska commented Sep 6, 2015

You would have to modify the calendar module pretty heavily. We rely on the operating system for locales, and I doubt we will be able to/willing to change that.

@felixfontein

This comment has been minimized.

Show comment
Hide comment
@felixfontein

felixfontein Sep 6, 2015

Contributor

How about a possibility to implement some calendar-related functions with a plugin?

Contributor

felixfontein commented Sep 6, 2015

How about a possibility to implement some calendar-related functions with a plugin?

@felixfontein

This comment has been minimized.

Show comment
Hide comment
@felixfontein

felixfontein Sep 6, 2015

Contributor

Another somewhat related thing is that I'd like DATE_FORMAT to be translatable. I for example use '%B %d, %Y at %H:%M' in one blog, which of course only works in english. Also for some languages/locales you want year/month/day in a different order than in others, so being able to specify a different DATE_FORMAT per language would be good.

Contributor

felixfontein commented Sep 6, 2015

Another somewhat related thing is that I'd like DATE_FORMAT to be translatable. I for example use '%B %d, %Y at %H:%M' in one blog, which of course only works in english. Also for some languages/locales you want year/month/day in a different order than in others, so being able to specify a different DATE_FORMAT per language would be good.

@da2x

This comment has been minimized.

Show comment
Hide comment
@da2x

da2x Sep 6, 2015

Contributor

IMHO, use ISO‐8601 everywhere all the time for all locales. Though of course not everyone agrees in this utilitarian approach, so localizeable DATE_FORMAT is something that should be supported.

Contributor

da2x commented Sep 6, 2015

IMHO, use ISO‐8601 everywhere all the time for all locales. Though of course not everyone agrees in this utilitarian approach, so localizeable DATE_FORMAT is something that should be supported.

@Kwpolska

This comment has been minimized.

Show comment
Hide comment
@Kwpolska

Kwpolska Sep 6, 2015

Member

Open a separate issue for localizing DATE_FORMAT (or even implement it yourself, it would take ~5 lines)

Member

Kwpolska commented Sep 6, 2015

Open a separate issue for localizing DATE_FORMAT (or even implement it yourself, it would take ~5 lines)

@felixfontein

This comment has been minimized.

Show comment
Hide comment
@felixfontein

felixfontein Sep 6, 2015

Contributor

I'll do that.

Contributor

felixfontein commented Sep 6, 2015

I'll do that.

@felixfontein

This comment has been minimized.

Show comment
Hide comment
@felixfontein

felixfontein Sep 6, 2015

Contributor

Ok, I looked a bit more in detail at what's happening. There are essentially two methods to print date/time related things:

  • calling post.formatted_date(format);
  • asking for a month's name in the archive plugin (via LocaleBorg).
    (Well, and there's date/time formatting in JavaScript via JS_DATE_FORMAT, but that's not in Nikola's hands, so let's ignore it.)

How about:

  1. making formatted_date a method of LocaleBorg, so that it is responsible for all date/time related formatting;
  2. allowing to add locale date/time handlers to LocaleBorg (for example by plugins, they could do that during set_site()) which are asked to handle month name resolution or date/time formatting for the languages they advertise (and if they don't want to, ask next handler and finally resolve to Python functions).

This makes it possible to write plugins which improve/handle a certain special locale without introducting too much infrastructure for it. What do you think? Especially @Kwpolska and @ralsina :)

Contributor

felixfontein commented Sep 6, 2015

Ok, I looked a bit more in detail at what's happening. There are essentially two methods to print date/time related things:

  • calling post.formatted_date(format);
  • asking for a month's name in the archive plugin (via LocaleBorg).
    (Well, and there's date/time formatting in JavaScript via JS_DATE_FORMAT, but that's not in Nikola's hands, so let's ignore it.)

How about:

  1. making formatted_date a method of LocaleBorg, so that it is responsible for all date/time related formatting;
  2. allowing to add locale date/time handlers to LocaleBorg (for example by plugins, they could do that during set_site()) which are asked to handle month name resolution or date/time formatting for the languages they advertise (and if they don't want to, ask next handler and finally resolve to Python functions).

This makes it possible to write plugins which improve/handle a certain special locale without introducting too much infrastructure for it. What do you think? Especially @Kwpolska and @ralsina :)

@ralsina

This comment has been minimized.

Show comment
Hide comment
@ralsina

ralsina Sep 8, 2015

Member

LGTM, should work.

Member

ralsina commented Sep 8, 2015

LGTM, should work.

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