forked from boyska/sito-hackit-17
Talks localize dates
This commit is contained in:
parent
760b7d0655
commit
bc99069bee
5 changed files with 40 additions and 12 deletions
|
@ -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.
|
find a bunch of people to ask to do translations when you need it.
|
||||||
|
|
||||||
.. talkgrid::
|
.. talkgrid::
|
||||||
|
:lang: en
|
||||||
|
|
||||||
.. talklist::
|
.. talklist::
|
||||||
|
:lang: en
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,8 @@ Leggi l'`invito a presentare dei contenuti
|
||||||
list <{filename}contatti.rst>`_
|
list <{filename}contatti.rst>`_
|
||||||
|
|
||||||
.. talkgrid::
|
.. talkgrid::
|
||||||
|
:lang: it
|
||||||
|
|
||||||
.. talklist::
|
.. talklist::
|
||||||
|
:lang: it
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,9 @@ import datetime
|
||||||
import shutil
|
import shutil
|
||||||
import time
|
import time
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
import locale
|
||||||
|
from contextlib import contextmanager
|
||||||
|
from babel.dates import format_date, format_datetime, format_time
|
||||||
|
|
||||||
import markdown
|
import markdown
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
|
@ -42,6 +45,15 @@ def memoize(function):
|
||||||
return wrapper
|
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
|
@memoize
|
||||||
def get_talk_names():
|
def get_talk_names():
|
||||||
return [name for name in os.listdir(TALKS_PATH)
|
return [name for name in os.listdir(TALKS_PATH)
|
||||||
|
@ -140,18 +152,23 @@ jinja_env = jinja2.Environment(
|
||||||
jinja_env.filters['markdown'] = lambda text: \
|
jinja_env.filters['markdown'] = lambda text: \
|
||||||
jinja2.Markup(markdown.Markdown(extensions=['meta']).
|
jinja2.Markup(markdown.Markdown(extensions=['meta']).
|
||||||
convert(text))
|
convert(text))
|
||||||
|
jinja_env.filters['dateformat'] = format_date
|
||||||
|
jinja_env.filters['datetimeformat'] = format_datetime
|
||||||
|
jinja_env.filters['timeformat'] = format_time
|
||||||
|
|
||||||
|
|
||||||
class TalkListDirective(Directive):
|
class TalkListDirective(Directive):
|
||||||
required_arguments = 0
|
|
||||||
optional_arguments = 0
|
|
||||||
final_argument_whitespace = True
|
final_argument_whitespace = True
|
||||||
has_content = True
|
has_content = True
|
||||||
|
option_spec = {
|
||||||
|
'lang': directives.unchanged
|
||||||
|
}
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
lang = self.options.get('lang', 'C')
|
||||||
tmpl = jinja_env.get_template('talk.html')
|
tmpl = jinja_env.get_template('talk.html')
|
||||||
return [
|
return [
|
||||||
nodes.raw('', tmpl.render(**get_talk_data(n)),
|
nodes.raw('', tmpl.render(lang=lang, **get_talk_data(n)),
|
||||||
format='html')
|
format='html')
|
||||||
for n in get_talk_names()
|
for n in get_talk_names()
|
||||||
]
|
]
|
||||||
|
@ -159,30 +176,34 @@ class TalkListDirective(Directive):
|
||||||
|
|
||||||
class TalkDirective(Directive):
|
class TalkDirective(Directive):
|
||||||
required_arguments = 1
|
required_arguments = 1
|
||||||
optional_arguments = 0
|
|
||||||
final_argument_whitespace = True
|
final_argument_whitespace = True
|
||||||
has_content = True
|
has_content = True
|
||||||
|
option_spec = {
|
||||||
|
'lang': directives.unchanged
|
||||||
|
}
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
lang = self.options.get('lang', 'C')
|
||||||
tmpl = jinja_env.get_template('talk.html')
|
tmpl = jinja_env.get_template('talk.html')
|
||||||
data = get_talk_data(self.arguments[0])
|
data = get_talk_data(self.arguments[0])
|
||||||
if data is None:
|
if data is None:
|
||||||
return []
|
return []
|
||||||
return [
|
return [
|
||||||
nodes.raw('', tmpl.render(**data),
|
nodes.raw('', tmpl.render(lang=lang, **data),
|
||||||
format='html')
|
format='html')
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class TalkGridDirective(Directive):
|
class TalkGridDirective(Directive):
|
||||||
'''A complete grid'''
|
'''A complete grid'''
|
||||||
required_arguments = 0
|
|
||||||
|
|
||||||
optional_arguments = 0
|
|
||||||
final_argument_whitespace = True
|
final_argument_whitespace = True
|
||||||
has_content = True
|
has_content = True
|
||||||
|
option_spec = {
|
||||||
|
'lang': directives.unchanged
|
||||||
|
}
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
lang = self.options.get('lang', 'C')
|
||||||
tmpl = jinja_env.get_template('grid.html')
|
tmpl = jinja_env.get_template('grid.html')
|
||||||
output = []
|
output = []
|
||||||
days = unique_attr(all_talks(), 'day')
|
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] = copy(talk)
|
||||||
times[position + i*GRID_STEP][roomnum]['skip'] = True
|
times[position + i*GRID_STEP][roomnum]['skip'] = True
|
||||||
|
|
||||||
|
#with setlocale(locale.normalize(lang)):
|
||||||
render = tmpl.render(times=times,
|
render = tmpl.render(times=times,
|
||||||
rooms=rooms,
|
rooms=rooms,
|
||||||
mintime=mintime, maxtime=maxtime,
|
mintime=mintime, maxtime=maxtime,
|
||||||
timestep=GRID_STEP,
|
timestep=GRID_STEP,
|
||||||
|
lang=lang,
|
||||||
)
|
)
|
||||||
output.append(nodes.raw('', u'<h4>%s</h4>' %
|
output.append(nodes.raw('', u'<h4>%s</h4>' %
|
||||||
day.strftime('%A %d').decode('utf8').title(),
|
format_date(day, format='full', locale=lang),
|
||||||
format='html'))
|
format='html'))
|
||||||
output.append(nodes.raw('', render, format='html'))
|
output.append(nodes.raw('', render, format='html'))
|
||||||
return output
|
return output
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
Babel==2.4.0
|
||||||
blinker==1.3
|
blinker==1.3
|
||||||
docutils==0.12
|
docutils==0.12
|
||||||
feedgenerator==1.7
|
feedgenerator==1.7
|
||||||
|
@ -8,8 +9,8 @@ pelican==3.5.0
|
||||||
Pygments==2.0.2
|
Pygments==2.0.2
|
||||||
python-dateutil==2.4.1
|
python-dateutil==2.4.1
|
||||||
pytz==2014.10
|
pytz==2014.10
|
||||||
|
PyYAML==3.12
|
||||||
six==1.9.0
|
six==1.9.0
|
||||||
smartypants==1.8.6
|
smartypants==1.8.6
|
||||||
typogrify==2.0.7
|
typogrify==2.0.7
|
||||||
Unidecode==0.4.17
|
Unidecode==0.4.17
|
||||||
PyYAML==3.12
|
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
<h3 class="talk-title">{{title}}</h3>
|
<h3 class="talk-title">{{title}}</h3>
|
||||||
<div class="talk-info">
|
<div class="talk-info">
|
||||||
{% if time is defined and day is defined %}
|
{% if time is defined and day is defined %}
|
||||||
{# Dai un nome meglio ai giorni #}
|
{# Vedi http://babel.pocoo.org/en/latest/dates.html #}
|
||||||
<p>Giorno {{day}} alle {{time.time()}}</p>
|
<p>{{day|dateformat(format='EEEE', locale=lang)}} - {{time.time()|timeformat(format='short', locale=lang)}}</p>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p><i>L'orario non è ancora stato fissato</i></p>
|
<p><i>L'orario non è ancora stato fissato</i></p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in a new issue