Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Roberto Alsina committed May 2, 2018
1 parent 390c733 commit 42d6e2b
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions 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.