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

Use Babel instead of system locale to format dates #3126

Merged
merged 10 commits into from
Aug 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Features
find a file (i.e. when an 404 error occurs).
* Better error messages for JSON download failures in ``nikola
plugin`` and ``nikola theme`` (Issue getnikola/plugins#282)
* Use Babel instead of the locale module to better handle
localizations (Issues #2606, #3121)
* Change ``DATE_FORMAT`` formats to CLDR formats (Issue #2606)

Bugfixes
--------
Expand Down
2 changes: 1 addition & 1 deletion docs/manual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@ Fancy Dates
Nikola can use various styles for presenting dates.

DATE_FORMAT
The date format to use if there is no JS or fancy dates are off. Compatible with Python’s ``strftime()`` syntax.
The date format to use if there is no JS or fancy dates are off. `Compatible with CLDR syntax. <http://cldr.unicode.org/translation/date-time>`_

JS_DATE_FORMAT
The date format to use if fancy dates are on. Compatible with ``moment.js`` syntax.
Expand Down
35 changes: 0 additions & 35 deletions dodo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import os
import fnmatch
import locale
import subprocess

DOIT_CONFIG = {
Expand Down Expand Up @@ -33,50 +32,16 @@ def task_pydocstyle():
}


def task_locale():
"""set environ locale vars used in nikola tests"""
def set_nikola_test_locales():
try:
out = subprocess.check_output(['locale', '-a'])
out = out.decode('utf-8')
locales = []
languages = set()
for line in out.splitlines():
if (line.endswith('.utf8') or line.endswith('.UTF-8')) and '_' in line:
lang = line.split('_')[0]
if lang not in languages:
try:
locale.setlocale(locale.LC_ALL, str(line))
except Exception:
continue
languages.add(lang)
locales.append((lang, line))
if len(locales) == 2:
break
if len(locales) != 2:
return False # task failed
else:
os.environ['NIKOLA_LOCALE_DEFAULT'] = ','.join(locales[0])
os.environ['NIKOLA_LOCALE_OTHER'] = ','.join(locales[1])
finally:
# restore to default locale
locale.resetlocale()

return {'actions': [set_nikola_test_locales], 'verbosity': 2}


def task_test():
"""run unit-tests using py.test"""
return {
'task_dep': ['locale'],
'actions': ['py.test tests/'],
}


def task_coverage():
"""run unit-tests using py.test, with coverage reporting"""
return {
'task_dep': ['locale'],
'actions': ['py.test --cov nikola --cov-report term-missing tests/'],
'verbosity': 2,
}
Expand Down
22 changes: 6 additions & 16 deletions nikola/conf.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,12 @@ TIMEZONE = ${TIMEZONE}
# FORCE_ISO8601 = False

# Date format used to display post dates. (translatable)
# (str used by datetime.datetime.strftime)
# DATE_FORMAT = '%Y-%m-%d %H:%M'
# Used by babel.dates, CLDR style: http://cldr.unicode.org/translation/date-time
# You can also use 'full', 'long', 'medium', or 'short'
# DATE_FORMAT = 'YYYY-MM-dd HH:mm'

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

# Date fanciness.
Expand All @@ -192,20 +193,9 @@ TIMEZONE = ${TIMEZONE}
# Your theme must support it, Bootstrap already does.
# DATE_FANCINESS = 0

# While Nikola can select a sensible locale for each language,
# sometimes explicit control can come handy.
# In this file we express locales in the string form that
# python's locales will accept in your OS, by example
# "en_US.utf8" in Unix-like OS, "English_United States" in Windows.
# LOCALES = dict mapping language --> explicit locale for the languages
# in TRANSLATIONS. You can omit one or more keys.
# LOCALE_FALLBACK = locale to use when an explicit locale is unavailable
# LOCALE_DEFAULT = locale to use for languages not mentioned in LOCALES; if
# not set the default Nikola mapping is used.

# Customize the locale/region used for a language.
# For example, to use British instead of US English: LOCALES = {'en': 'en_GB'}
# LOCALES = {}
# LOCALE_FALLBACK = None
# LOCALE_DEFAULT = None

# One or more folders containing files to be copied as-is into the output.
# The format is a dictionary of {source: relative destination}.
Expand Down
6 changes: 2 additions & 4 deletions nikola/data/themes/base/messages/messages_ar.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"Posts about %s": "مقالات عن %s",
"Posts by %s": "مقالات بواسطة %s",
"Posts for year %s": "مقالات سنة %s",
"Posts for {month} {day}, {year}": "",
"Posts for {month} {year}": "",
"Posts for {month_day_year}": "",
"Posts for {month_year}": "",
"Previous post": "المقالة السابقة",
"Previous": "السابق",
"Publication date": "تاريخ النشر",
Expand All @@ -45,6 +45,4 @@
"Write your post here.": "أكتب مقالك هنا",
"old posts, page %d": "مقالات قديمة, صفحة %d",
"page %d": "صفحة %d",
"{month} {day}, {year}": "",
"{month} {year}": "",
}
6 changes: 2 additions & 4 deletions nikola/data/themes/base/messages/messages_az.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"Posts about %s": "%s ilə bağlı yazılar",
"Posts by %s": "%s tərəfindən yazılmış yazılar",
"Posts for year %s": "%s ilindəki yazılar",
"Posts for {month} {day}, {year}": "{month} {day}, {year} üçün yazılar",
"Posts for {month} {year}": "{month} {year} üçün yazılar",
"Posts for {month_day_year}": "{month_day_year} üçün yazılar",
"Posts for {month_year}": "{month_year} üçün yazılar",
"Previous post": "Əvvəlki yazı",
"Previous": "Öncəki",
"Publication date": "Buraxılış tarixi",
Expand All @@ -45,6 +45,4 @@
"Write your post here.": "Öz məqaləni bura yaz",
"old posts, page %d": "köhnə yazılar, səhifə %s",
"page %d": "səhifə %d",
"{month} {day}, {year}": "{month} {day}, {year}",
"{month} {year}": "{month} {year}",
}
6 changes: 2 additions & 4 deletions nikola/data/themes/base/messages/messages_bg.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"Posts about %s": "Публикации относно %s",
"Posts by %s": "Публикации от %s",
"Posts for year %s": "Публикации за %s година",
"Posts for {month} {day}, {year}": "Публикации от {day} {month} {year}",
"Posts for {month} {year}": "Публикации за {month} {year}",
"Posts for {month_day_year}": "Публикации от {month_day_year}",
"Posts for {month_year}": "Публикации за {month_year}",
"Previous post": "Предишна публикация",
"Previous": "",
"Publication date": "Дата на публикуване",
Expand All @@ -45,6 +45,4 @@
"Write your post here.": "Напиши тук текста на твоята публикация.",
"old posts, page %d": "стари публикации, страница %d",
"page %d": "страница %d",
"{month} {day}, {year}": "",
"{month} {year}": "",
}
6 changes: 2 additions & 4 deletions nikola/data/themes/base/messages/messages_br.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"Posts about %s": "",
"Posts by %s": "",
"Posts for year %s": "",
"Posts for {month} {day}, {year}": "",
"Posts for {month} {year}": "",
"Posts for {month_day_year}": "",
"Posts for {month_year}": "",
"Previous post": "",
"Previous": "",
"Publication date": "",
Expand All @@ -45,6 +45,4 @@
"Write your post here.": "",
"old posts, page %d": "",
"page %d": "",
"{month} {day}, {year}": "",
"{month} {year}": "",
}
6 changes: 2 additions & 4 deletions nikola/data/themes/base/messages/messages_bs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"Posts about %s": "Objave o %s",
"Posts by %s": "Objave prema %s",
"Posts for year %s": "Objave u godini %s",
"Posts for {month} {day}, {year}": "Objave za {day}.{month}.{year}",
"Posts for {month} {year}": "Objave za {month} {year}",
"Posts for {month_day_year}": "Objave za {month_day_year}",
"Posts for {month_year}": "Objave za {month_year}",
"Previous post": "Prethodni članak",
"Previous": "",
"Publication date": "Datum objavljivanja",
Expand All @@ -45,6 +45,4 @@
"Write your post here.": "Vaš članak napišite ovdje.",
"old posts, page %d": "stare objave, strana %d",
"page %d": "strana %d",
"{month} {day}, {year}": "",
"{month} {year}": "",
}
6 changes: 2 additions & 4 deletions nikola/data/themes/base/messages/messages_ca.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"Posts about %s": "Entrades sobre %s",
"Posts by %s": "Entrades per %s",
"Posts for year %s": "Entrades de l'any %s",
"Posts for {month} {day}, {year}": "Entrades per {month} {day}, {year}",
"Posts for {month} {year}": "Publicat en {month} {year}",
"Posts for {month_day_year}": "Entrades per {month_day_year}",
"Posts for {month_year}": "Publicat en {month_year}",
"Previous post": "Entrada anterior",
"Previous": "",
"Publication date": "Data de publicació",
Expand All @@ -45,6 +45,4 @@
"Write your post here.": "Escribiu la vostra entrada aquí",
"old posts, page %d": "entrades antigues, pàgina %d",
"page %d": "pàgina %d",
"{month} {day}, {year}": "",
"{month} {year}": "",
}
6 changes: 2 additions & 4 deletions nikola/data/themes/base/messages/messages_cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"Posts about %s": "Příspěvky o %s",
"Posts by %s": "",
"Posts for year %s": "Příspěvky v roce %s",
"Posts for {month} {day}, {year}": "Příspěvky v {month} {day}, {year}",
"Posts for {month} {year}": "Příspěvky v {month} {year}",
"Posts for {month_day_year}": "Příspěvky v {month_day_year}",
"Posts for {month_year}": "Příspěvky v {month_year}",
"Previous post": "Předchozí příspěvek",
"Previous": "",
"Publication date": "Datum zveřejnění",
Expand All @@ -45,6 +45,4 @@
"Write your post here.": "",
"old posts, page %d": "staré příspěvky, strana %d",
"page %d": "strana %d",
"{month} {day}, {year}": "",
"{month} {year}": "",
}
6 changes: 2 additions & 4 deletions nikola/data/themes/base/messages/messages_da.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"Posts about %s": "Indlæg om %s",
"Posts by %s": "",
"Posts for year %s": "Indlæg for %s",
"Posts for {month} {day}, {year}": "Indlæs for {month} {day}, {year}",
"Posts for {month} {year}": "Indlæg for {month} {year}",
"Posts for {month_day_year}": "Indlæs for {month_day_year}",
"Posts for {month_year}": "Indlæg for {month_year}",
"Previous post": "Tidligere indlæg",
"Previous": "",
"Publication date": "Udgivelsesdato",
Expand All @@ -45,6 +45,4 @@
"Write your post here.": "",
"old posts, page %d": "gamle indlæg, side %d",
"page %d": "side %d",
"{month} {day}, {year}": "",
"{month} {year}": "",
}
6 changes: 2 additions & 4 deletions nikola/data/themes/base/messages/messages_de.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"Posts about %s": "Einträge über %s",
"Posts by %s": "Einträge von %s",
"Posts for year %s": "Einträge aus dem Jahr %s",
"Posts for {month} {day}, {year}": "Einträge vom {day}. {month} {year}",
"Posts for {month} {year}": "Einträge aus {month} {year}",
"Posts for {month_day_year}": "Einträge vom {month_day_year}",
"Posts for {month_year}": "Einträge aus {month_year}",
"Previous post": "Vorheriger Eintrag",
"Previous": "Vorheriger Eintrag",
"Publication date": "Veröffentlichungsdatum",
Expand All @@ -45,6 +45,4 @@
"Write your post here.": "Schreibe hier deinen Eintrag hin.",
"old posts, page %d": "Ältere Einträge, Seite %d",
"page %d": "Seite %d",
"{month} {day}, {year}": "{day}. {month} {year}",
"{month} {year}": "{month} {year}",
}
6 changes: 2 additions & 4 deletions nikola/data/themes/base/messages/messages_el.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"Posts about %s": "Αναρτήσεις για %s",
"Posts by %s": "",
"Posts for year %s": "Αναρτήσεις για το έτος %s",
"Posts for {month} {day}, {year}": "Αναρτήσεις στις {day} {month}, {year}",
"Posts for {month} {year}": "Αναρτήσεις για τον {month} του {year}",
"Posts for {month_day_year}": "Αναρτήσεις στις {month_day_year}",
"Posts for {month_year}": "Αναρτήσεις για τον {month_year}",
"Previous post": "Προηγούμενη ανάρτηση",
"Previous": "",
"Publication date": "Ημερομηνία δημοσίευσης",
Expand All @@ -45,6 +45,4 @@
"Write your post here.": "",
"old posts, page %d": "σελίδα παλαιότερων αναρτήσεων %d",
"page %d": "σελίδα %d",
"{month} {day}, {year}": "",
"{month} {year}": "",
}
6 changes: 2 additions & 4 deletions nikola/data/themes/base/messages/messages_en.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"Posts about %s": "Posts about %s",
"Posts by %s": "Posts by %s",
"Posts for year %s": "Posts for year %s",
"Posts for {month} {day}, {year}": "Posts for {month} {day}, {year}",
"Posts for {month} {year}": "Posts for {month} {year}",
"Posts for {month_day_year}": "Posts for {month_day_year}",
"Posts for {month_year}": "Posts for {month_year}",
"Previous post": "Previous post",
"Previous": "Previous",
"Publication date": "Publication date",
Expand All @@ -45,6 +45,4 @@
"Write your post here.": "Write your post here.",
"old posts, page %d": "old posts, page %d",
"page %d": "page %d",
"{month} {day}, {year}": "{month} {day}, {year}",
"{month} {year}": "{month} {year}",
}
14 changes: 6 additions & 8 deletions nikola/data/themes/base/messages/messages_eo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"(active)": "(aktiva)",
"Also available in:": "Ankaŭ disponebla en:",
"Archive": "Arkivo",
"Atom feed": "",
"Atom feed": "Atom fluo",
"Authors": "Aŭtoroj",
"Categories": "Kategorioj",
"Comments": "Komentoj",
Expand All @@ -15,7 +15,7 @@
"More posts about %s": "Pli da artikoloj pri %s",
"Newer posts": "Pli novaj artikoloj",
"Next post": "Venonta artikolo",
"Next": "",
"Next": "Venonta",
"No posts found.": "Neniu artikoloj trovitaj.",
"Nothing found.": "Nenio trovita.",
"Older posts": "Pli malnovaj artikoloj",
Expand All @@ -24,10 +24,10 @@
"Posts about %s": "Artikoloj pri %s",
"Posts by %s": "Artikoloj de %s",
"Posts for year %s": "Artikoloj de la jaro %s",
"Posts for {month} {day}, {year}": "Artikoloj de la {day}a de {month} {year}",
"Posts for {month} {year}": "Artikoloj de {month} {year}",
"Posts for {month_day_year}": "Artikoloj de la {month_day_year}",
"Posts for {month_year}": "Artikoloj de {month_year}",
"Previous post": "Antaŭa artikolo",
"Previous": "",
"Previous": "Antaŭa",
"Publication date": "Eldona dato",
"RSS feed": "RSS fluo",
"Read in English": "Legu ĝin en Esperanto",
Expand All @@ -39,12 +39,10 @@
"Tags": "Etikedoj",
"Toggle navigation": "Ŝalti menuon",
"Uncategorized": "Sen kategorioj",
"Up": "",
"Up": "Supren",
"Updates": "Ĝisdatigoj",
"Write your page here.": "Skribu tie vian paĝon.",
"Write your post here.": "Skribu tie vian artikolon.",
"old posts, page %d": "%da paĝo de malnovaj artikoloj",
"page %d": "paĝo %d",
"{month} {day}, {year}": "",
"{month} {year}": "",
}
6 changes: 2 additions & 4 deletions nikola/data/themes/base/messages/messages_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"Posts about %s": "Publicaciones sobre %s",
"Posts by %s": "Publicaciones de %s",
"Posts for year %s": "Publicaciones del año %s",
"Posts for {month} {day}, {year}": "Publicaciones del {day} de {month} de {year}",
"Posts for {month} {year}": "Posts de {month} de {year}",
"Posts for {month_day_year}": "Publicaciones del {month_day_year}",
"Posts for {month_year}": "Posts de {month_year}",
"Previous post": "Publicación anterior",
"Previous": "Anterior",
"Publication date": "Fecha de publicación",
Expand All @@ -45,6 +45,4 @@
"Write your post here.": "Escriba su publicación aquí.",
"old posts, page %d": "publicaciones antiguas, página %d",
"page %d": "página %d",
"{month} {day}, {year}": "{month} {day}, {year}",
"{month} {year}": "{month} {year}",
}
Loading