Permalink
Browse files

* Added 'translations' option to pass languages to Jinja2's i18n exte…

…nsion.
  • Loading branch information...
1 parent 696add2 commit 608b99ee8ea5ec620a909406810b81b44c6a75fe @breily breily committed Mar 13, 2009
Showing with 16 additions and 1 deletion.
  1. +6 −0 doc/2-configuration.md
  2. +10 −1 juno.py
View
6 doc/2-configuration.md
@@ -104,6 +104,12 @@ Template Options
* 'auto_reload_templates': True
=> If True, templates are automatically reloaded when they change.
+ * 'translations': []
+ => A list of translation objects to be passed to Jinja2's i18n extension.
+ A translation object is one returned by gettext.translation or the
+ equivalent. If the list is empty, the i18n extension is not enabled.
+ This option only acts on Jinja2 currently.
+
* 'template_kwargs': {}
=> Allows you to pass custom keyword arguments to the template lookup
object (Environment for Jinja2, TemplateLookup for Mako).
View
11 juno.py
@@ -43,6 +43,7 @@ def join_app_path(path):
'get_template_handler': _get_template_handler,
'render_template_handler': _render_template_handler,
'auto_reload_templates': True,
+ 'translations': [],
'template_kwargs': {},
'template_root': join_app_path('templates/'),
'404_template': '404.html',
@@ -78,14 +79,22 @@ def setup_static(self):
def setup_templates(self):
if self.config['template_lib'] == 'jinja2':
import jinja2
+ # If the user specified translation objects, load i18n extension
+ if len(self.config['translations']) != 0:
+ extensions = ['jinja2.ext.i18n']
+ else:
+ extensions = ()
self.config['template_env'] = jinja2.Environment(
loader = jinja2.FileSystemLoader(
searchpath = self.config['template_root'],
- encoding = self.config['charset']
+ encoding = self.config['charset'],
),
auto_reload = self.config['auto_reload_templates'],
+ extensions = extensions,
**self.config['template_kwargs']
)
+ for translation in self.config['translations']:
+ self.config['template_env'].install_gettext_translations(translation)
if self.config['template_lib'] == 'mako':
import mako.lookup
self.config['template_env'] = mako.lookup.TemplateLookup(

0 comments on commit 608b99e

Please sign in to comment.