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'

%s

' % - day.strftime('%A %d').decode('utf8').title(), + format_date(day, format='full', locale=lang), format='html')) output.append(nodes.raw('', render, format='html')) return output diff --git a/requirements.txt b/requirements.txt index 89e5a29..f464b75 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +Babel==2.4.0 blinker==1.3 docutils==0.12 feedgenerator==1.7 @@ -8,8 +9,8 @@ pelican==3.5.0 Pygments==2.0.2 python-dateutil==2.4.1 pytz==2014.10 +PyYAML==3.12 six==1.9.0 smartypants==1.8.6 typogrify==2.0.7 Unidecode==0.4.17 -PyYAML==3.12 diff --git a/talks/_templates/talk.html b/talks/_templates/talk.html index a77031c..1e2eacb 100644 --- a/talks/_templates/talk.html +++ b/talks/_templates/talk.html @@ -2,8 +2,8 @@

{{title}}

{% if time is defined and day is defined %} - {# Dai un nome meglio ai giorni #} -

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 %}