Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…nsion.
  • Loading branch information...
commit 608b99ee8ea5ec620a909406810b81b44c6a75fe 1 parent 696add2
Brian Reily breily authored

Showing 2 changed files with 16 additions and 1 deletion. Show diff stats Hide diff stats

  1. +6 0 doc/2-configuration.md
  2. +10 1 juno.py
6 doc/2-configuration.md
Source Rendered
@@ -104,6 +104,12 @@ Template Options
104 104 * 'auto_reload_templates': True
105 105 => If True, templates are automatically reloaded when they change.
106 106
  107 + * 'translations': []
  108 + => A list of translation objects to be passed to Jinja2's i18n extension.
  109 + A translation object is one returned by gettext.translation or the
  110 + equivalent. If the list is empty, the i18n extension is not enabled.
  111 + This option only acts on Jinja2 currently.
  112 +
107 113 * 'template_kwargs': {}
108 114 => Allows you to pass custom keyword arguments to the template lookup
109 115 object (Environment for Jinja2, TemplateLookup for Mako).
11 juno.py
@@ -43,6 +43,7 @@ def join_app_path(path):
43 43 'get_template_handler': _get_template_handler,
44 44 'render_template_handler': _render_template_handler,
45 45 'auto_reload_templates': True,
  46 + 'translations': [],
46 47 'template_kwargs': {},
47 48 'template_root': join_app_path('templates/'),
48 49 '404_template': '404.html',
@@ -78,14 +79,22 @@ def setup_static(self):
78 79 def setup_templates(self):
79 80 if self.config['template_lib'] == 'jinja2':
80 81 import jinja2
  82 + # If the user specified translation objects, load i18n extension
  83 + if len(self.config['translations']) != 0:
  84 + extensions = ['jinja2.ext.i18n']
  85 + else:
  86 + extensions = ()
81 87 self.config['template_env'] = jinja2.Environment(
82 88 loader = jinja2.FileSystemLoader(
83 89 searchpath = self.config['template_root'],
84   - encoding = self.config['charset']
  90 + encoding = self.config['charset'],
85 91 ),
86 92 auto_reload = self.config['auto_reload_templates'],
  93 + extensions = extensions,
87 94 **self.config['template_kwargs']
88 95 )
  96 + for translation in self.config['translations']:
  97 + self.config['template_env'].install_gettext_translations(translation)
89 98 if self.config['template_lib'] == 'mako':
90 99 import mako.lookup
91 100 self.config['template_env'] = mako.lookup.TemplateLookup(

0 comments on commit 608b99e

Please sign in to comment.
Something went wrong with that request. Please try again.