diff --git a/content/pages/programma.en.rst b/content/pages/programma.en.rst index 44eda1b..3665781 100644 --- a/content/pages/programma.en.rst +++ b/content/pages/programma.en.rst @@ -18,7 +18,9 @@ Hackmeeting (still) hasn't a proper translation system, but you can find a bunch of people to ask to do translations when you need it. .. talkgrid:: + :lang: en .. talklist:: + :lang: en diff --git a/content/pages/programma.rst b/content/pages/programma.rst index a98196e..1651a72 100644 --- a/content/pages/programma.rst +++ b/content/pages/programma.rst @@ -13,6 +13,8 @@ Leggi l'`invito a presentare dei contenuti list <{filename}contatti.rst>`_ .. talkgrid:: + :lang: it .. talklist:: + :lang: it diff --git a/plugins/talks.py b/plugins/talks.py index 971d37b..0efe43f 100644 --- a/plugins/talks.py +++ b/plugins/talks.py @@ -12,6 +12,9 @@ import datetime import shutil import time from copy import copy +import locale +from contextlib import contextmanager +from babel.dates import format_date, format_datetime, format_time import markdown from docutils import nodes @@ -42,6 +45,15 @@ def memoize(function): return wrapper +@contextmanager +def setlocale(name): + saved = locale.setlocale(locale.LC_ALL) + try: + yield locale.setlocale(locale.LC_ALL, name) + finally: + locale.setlocale(locale.LC_ALL, saved) + + @memoize def get_talk_names(): return [name for name in os.listdir(TALKS_PATH) @@ -140,18 +152,23 @@ jinja_env = jinja2.Environment( jinja_env.filters['markdown'] = lambda text: \ jinja2.Markup(markdown.Markdown(extensions=['meta']). convert(text)) +jinja_env.filters['dateformat'] = format_date +jinja_env.filters['datetimeformat'] = format_datetime +jinja_env.filters['timeformat'] = format_time class TalkListDirective(Directive): - required_arguments = 0 - optional_arguments = 0 final_argument_whitespace = True has_content = True + option_spec = { + 'lang': directives.unchanged + } def run(self): + lang = self.options.get('lang', 'C') tmpl = jinja_env.get_template('talk.html') return [ - nodes.raw('', tmpl.render(**get_talk_data(n)), + nodes.raw('', tmpl.render(lang=lang, **get_talk_data(n)), format='html') for n in get_talk_names() ] @@ -159,30 +176,34 @@ class TalkListDirective(Directive): class TalkDirective(Directive): required_arguments = 1 - optional_arguments = 0 final_argument_whitespace = True has_content = True + option_spec = { + 'lang': directives.unchanged + } def run(self): + lang = self.options.get('lang', 'C') tmpl = jinja_env.get_template('talk.html') data = get_talk_data(self.arguments[0]) if data is None: return [] return [ - nodes.raw('', tmpl.render(**data), + nodes.raw('', tmpl.render(lang=lang, **data), format='html') ] class TalkGridDirective(Directive): '''A complete grid''' - required_arguments = 0 - - optional_arguments = 0 final_argument_whitespace = True has_content = True + option_spec = { + 'lang': directives.unchanged + } def run(self): + lang = self.options.get('lang', 'C') tmpl = jinja_env.get_template('grid.html') output = [] days = unique_attr(all_talks(), 'day') @@ -222,13 +243,15 @@ class TalkGridDirective(Directive): times[position + i*GRID_STEP][roomnum] = copy(talk) times[position + i*GRID_STEP][roomnum]['skip'] = True + #with setlocale(locale.normalize(lang)): render = tmpl.render(times=times, rooms=rooms, mintime=mintime, maxtime=maxtime, timestep=GRID_STEP, + lang=lang, ) output.append(nodes.raw('', u'
Giorno {{day}} alle {{time.time()}}
+ {# Vedi http://babel.pocoo.org/en/latest/dates.html #} +{{day|dateformat(format='EEEE', locale=lang)}} - {{time.time()|timeformat(format='short', locale=lang)}}
{% else %}L'orario non รจ ancora stato fissato
{% endif %}