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

Making DATE_FORMAT translatable. #2033

Merged
merged 3 commits into from Sep 6, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -8,6 +8,7 @@ Features
* Made CATEGORY_PATH translatable (Issue #1914)
* Display post counts for archive links (Issue #2011)
* Document link/path handlers (Issue #2008)
* Made DATE_FORMAT and JS_DATE_FORMAT translatable (Issue #2032)

Bugfixes
--------
Expand Down
4 changes: 2 additions & 2 deletions nikola/conf.py.in
Expand Up @@ -140,11 +140,11 @@ TIMEZONE = ${TIMEZONE}
# Note that this does not affect DATE_FORMAT.
# FORCE_ISO8601 = False

# Date format used to display post dates.
# Date format used to display post dates. (translatable)
# (str used by datetime.datetime.strftime)
# DATE_FORMAT = '%Y-%m-%d %H:%M'

# Date format used to display post dates, if local dates are used.
# Date format used to display post dates, if local dates are used. (translatable)
# (str used by moment.js)
# JS_DATE_FORMAT = 'YYYY-MM-DD HH:mm'

Expand Down
6 changes: 5 additions & 1 deletion nikola/nikola.py
Expand Up @@ -553,6 +553,8 @@ def __init__(self, **config):
# PATH options (Issue #1914)
'TAG_PATH',
'CATEGORY_PATH',
'DATE_FORMAT',
'JS_DATE_FORMAT',
)

self._GLOBAL_CONTEXT_TRANSLATABLE = ('blog_author',
Expand All @@ -564,7 +566,9 @@ def __init__(self, **config):
'social_buttons_code',
'search_form',
'body_end',
'extra_head_data',)
'extra_head_data',
'date_format',
'js_date_format',)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m afraid the tests fail because JS_DATE_FORMAT is not that easy, you would need special casing to do json.dumps() when the translatable context is evaluated and drop the _GLOBAL_CONTEXT setting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now did the json.dumps() before creating the TranslatableSetting object creations. This way, I only have to change a bit in nikola.py, but not in all places where _GLOBAL_CONTEXT is converted to a local context (that happens several times in nikola.py and in at least four plugins).

# WARNING: navigation_links SHOULD NOT be added to the list above.
# Themes ask for [lang] there and we should provide it.

Expand Down