Permalink
Browse files

Merge pull request #51 from vindolin/master

Option for newstyle gettext calls
  • Loading branch information...
2 parents 443090d + 4b4f40a commit 4a3a4c82cf06ee89f81e81be954addaaa087ebcc @domenkozar domenkozar committed Dec 7, 2012
Showing with 40 additions and 2 deletions.
  1. +1 −1 CHANGES.txt
  2. +10 −0 docs/index.rst
  3. +4 −1 pyramid_jinja2/__init__.py
  4. +1 −0 pyramid_jinja2/tests/templates/newstyle.jinja2
  5. +24 −0 pyramid_jinja2/tests/test_it.py
View
@@ -1,7 +1,7 @@
1.6 (unreleased)
================
-- Nothing changed yet.
+- Add `jinja2.newstyle` setting to enable newstyle gettext calls
1.5 (2012-11-24)
View
@@ -407,6 +407,16 @@ temporary directory. See :py:class:`jinja2.FileSystemBytecodeCache`.
strategy (such as cron) to check and remove such files.
+.. _setting_jinja2_newstyle:
+
+jinja2.newstyle
+-----------------------
+
+``true`` or ``false`` to enable the use of newstyle gettext calls. Defaults to
+``false``.
+
+See `Newstyle Gettext http://jinja.pocoo.org/docs/extensions/#newstyle-gettext`
+
.. _jinja2_filters:
Jinja2 Filters
@@ -295,6 +295,9 @@ def _get_or_build_default_environment(registry):
# clear cache on exit
atexit.register(kw['bytecode_cache'].clear)
+ # should newstyle gettext calls be enabled?
+ newstyle = asbool(settings.get('jinja2.newstyle', False))
+
environment = Environment(loader=loader,
auto_reload=reload_templates,
extensions=extensions,
@@ -303,7 +306,7 @@ def _get_or_build_default_environment(registry):
# register pyramid i18n functions
wrapper = GetTextWrapper(domain=domain)
- environment.install_gettext_callables(wrapper.gettext, wrapper.ngettext)
+ environment.install_gettext_callables(wrapper.gettext, wrapper.ngettext, newstyle=newstyle)
# register global repository for templates
if package is not None:
@@ -0,0 +1 @@
+{{ gettext('my hovercraft is full of %(what)s!', what=what) }}
@@ -517,6 +517,30 @@ def stack(self):
self.assertEqual(pf.caller_package(), xml)
+class TestNewstyle(unittest.TestCase):
+ def test_it(self):
+ from pyramid.config import Configurator
+ from pyramid_jinja2 import includeme
+ from webtest import TestApp
+ import os
+
+ here = os.path.abspath(os.path.dirname(__file__))
+ templates_dir = os.path.join(here, 'templates')
+
+ def myview(request):
+ return {'what': 'eels'}
+
+ config = Configurator(settings={
+ 'jinja2.directories': templates_dir,
+ 'jinja2.newstyle': True})
+ includeme(config)
+ config.add_view(view=myview, renderer='newstyle.jinja2')
+
+ app = config.make_wsgi_app()
+ testapp = TestApp(app)
+ self.assertEqual(testapp.get('/').body.decode('utf-8'), text_('my hovercraft is full of eels!'))
+
+
class MiscTests(Base, unittest.TestCase):
def test_add_jinja2_extension(self):

0 comments on commit 4a3a4c8

Please sign in to comment.