Skip to content

Commit

Permalink
Fixed a bug in the i18n extraction option handling and added a silent…
Browse files Browse the repository at this point in the history
… option.
  • Loading branch information
mitsuhiko committed Dec 15, 2011
1 parent 7d268be commit 1161915
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -9,6 +9,7 @@ Version 2.7
separately in order to work in combination with module loaders as
advertised.
- Fixed filesizeformat.
- Added a non-silent option for babel extraction.

Version 2.6
-----------
Expand Down
2 changes: 1 addition & 1 deletion docs/extensions.rst
Expand Up @@ -34,7 +34,7 @@ translatable and calls `gettext`.

After enabling dummy `_` function that forwards calls to `gettext` is added
to the environment globals. An internationalized application then has to
provide at least an `gettext` and optoinally a `ngettext` function into the
provide at least an `gettext` and optionally a `ngettext` function into the
namespace. Either globally or for each rendering.

Environment Methods
Expand Down
9 changes: 9 additions & 0 deletions docs/integration.rst
Expand Up @@ -38,6 +38,15 @@ that templates use ``%`` as `line_statement_prefix` you can use this code:
of import paths as `extensions` value. The i18n extension is added
automatically.

.. versionchanged:: 2.7

Until 2.7 template syntax errors were always ignored. This was done
since many people are dropping non template html files into the
templates folder and it would randomly fail. The assumption was that
testsuites will catch syntax errors in templates anyways. If you don't
want that behavior you can add ``silent=false`` to the settings and
exceptions are propagated.

.. _mapping file: http://babel.edgewall.org/wiki/Documentation/messages.html#extraction-method-mapping-and-configuration

Pylons
Expand Down
10 changes: 9 additions & 1 deletion jinja2/ext.py
Expand Up @@ -552,6 +552,10 @@ def babel_extract(fileobj, keywords, comment_tags, options):
The `newstyle_gettext` flag can be set to `True` to enable newstyle
gettext calls.
.. versionchanged:: 2.7
A `silent` option can now be provided. If set to `False` template
syntax errors are propagated instead of being ignored.
:param fileobj: the file-like object the messages should be extracted from
:param keywords: a list of keywords (i.e. function names) that should be
recognized as translation functions
Expand All @@ -571,8 +575,10 @@ def babel_extract(fileobj, keywords, comment_tags, options):
extensions.add(InternationalizationExtension)

def getbool(options, key, default=False):
options.get(key, str(default)).lower() in ('1', 'on', 'yes', 'true')
return options.get(key, str(default)).lower() in \
('1', 'on', 'yes', 'true')

silent = getbool(options, 'silent', True)
environment = Environment(
options.get('block_start_string', BLOCK_START_STRING),
options.get('block_end_string', BLOCK_END_STRING),
Expand All @@ -596,6 +602,8 @@ def getbool(options, key, default=False):
node = environment.parse(source)
tokens = list(environment.lex(environment.preprocess(source)))
except TemplateSyntaxError, e:
if not silent:
raise
# skip templates with syntax errors
return

Expand Down

0 comments on commit 1161915

Please sign in to comment.