Skip to content
Permalink
Browse files

Merge branch 'master' into plugin-for-2761

  • Loading branch information
felixfontein committed May 3, 2018
2 parents 685be9c + 3dcdeb7 commit 8b327b9f123c813ee1bd158da9911c9370912be1
Showing with 16 additions and 9 deletions.
  1. +13 −8 v7/babeldates/babeldates.py
  2. +2 −1 v7/babeldates/requirements.txt
  3. +1 −0 v7/bbcode/requirements.txt
@@ -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)
@@ -1 +1,2 @@
babel
babel

@@ -1 +1,2 @@
bbcode

0 comments on commit 8b327b9

Please sign in to comment.