Skip to content
Permalink
Browse files
lint
  • 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/babeldates.py
@@ -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):
self.name = 'babelDates'

def set_site(self, site):
self.site = site
if self.site.config['DATE_FANCINESS'] == 0 and not self.site.config.get('BABEL_DATE_FORMAT') is None:
babel_date_format = utils.TranslatableSetting('BABEL_DATE_FORMAT', self.site.config['BABEL_DATE_FORMAT'], self.site.config['TRANSLATIONS'])
babel_date_format = utils.TranslatableSetting(
'BABEL_DATE_FORMAT', self.site.config['BABEL_DATE_FORMAT'], self.site.config['TRANSLATIONS'])
for lang in self.site.config['TRANSLATIONS']:
try:
self.site.config['DATE_FORMAT'][lang] = babel_date_format(lang)
self.site.config['DATE_FORMAT'][lang] = babel_date_format(
lang)
except KeyError:
self.site.config['DATE_FORMAT'][lang] = 'medium'
utils.LocaleBorg().add_handler(formatted_date_handler = self.babel_date_formatter)
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]
else:
norm_locale = self.site.config['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.