Skip to content
Browse files
  • Loading branch information
ralsina committed May 2, 2018
1 parent 390c733 commit 42d6e2b38bf01976b44af29480f4e1c09f42c230
Showing with 13 additions and 8 deletions.
  1. +13 −8 v7/babeldates/
@@ -1,32 +1,37 @@
from nikola.plugin_categories import ConfigPlugin
from nikola import utils
import locale
import datetime
from babel import Locale, dates
import platform

from babel import dates

from nikola import utils
from nikola.plugin_categories import ConfigPlugin

class BabelDates(ConfigPlugin):
Use Babel to format dates

def __init__(self): = 'babelDates'

def set_site(self, site): = site
if['DATE_FANCINESS'] == 0 and not'BABEL_DATE_FORMAT') is None:
babel_date_format = utils.TranslatableSetting('BABEL_DATE_FORMAT',['BABEL_DATE_FORMAT'],['TRANSLATIONS'])
babel_date_format = utils.TranslatableSetting(
for lang in['TRANSLATIONS']:
try:['DATE_FORMAT'][lang] = babel_date_format(lang)['DATE_FORMAT'][lang] = babel_date_format(
except KeyError:['DATE_FORMAT'][lang] = 'medium'
utils.LocaleBorg().add_handler(formatted_date_handler = self.babel_date_formatter)
super(BabelDates, self).set_site(site)

def babel_date_formatter(self, date_format, date, lang):
if platform.system() == 'Windows':
norm_locale = locale.normalize(lang).split('.')[0]
norm_locale =['LOCALES'][lang]
return dates.format_datetime(date, format = date_format, locale = norm_locale)
return dates.format_datetime(date, format=date_format, locale=norm_locale)

0 comments on commit 42d6e2b

Please sign in to comment.