diff --git a/tests/test_stack/i18n/de/LC_MESSAGES/tests.test_stack.mo b/tests/test_stack/i18n/de/LC_MESSAGES/tests.test_stack.mo new file mode 100644 index 00000000..e0ccf97b Binary files /dev/null and b/tests/test_stack/i18n/de/LC_MESSAGES/tests.test_stack.mo differ diff --git a/tests/test_stack/i18n/de/LC_MESSAGES/tests.test_stack.po b/tests/test_stack/i18n/de/LC_MESSAGES/tests.test_stack.po new file mode 100644 index 00000000..5e4ff6a8 --- /dev/null +++ b/tests/test_stack/i18n/de/LC_MESSAGES/tests.test_stack.po @@ -0,0 +1,19 @@ +# German translations for tests. +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: tests 0.0\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2009-07-07 07:07+0700\n" +"PO-Revision-Date: 2009-07-07 07:17+0700\n" +"Last-Translator: FULL NAME \n" +"Language-Team: de \n" +"Plural-Forms: nplurals=2; plural=(n != 1)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 0.9.4\n" + +#: test_stack/rendering/templates/jinja_i18n.jinja:1 +msgid "Your application is now running" +msgstr "Ihre Anwendung läuft jetzt einwandfrei" diff --git a/tests/test_stack/rendering/controllers/root.py b/tests/test_stack/rendering/controllers/root.py index d48de3f6..94820a6d 100644 --- a/tests/test_stack/rendering/controllers/root.py +++ b/tests/test_stack/rendering/controllers/root.py @@ -1,6 +1,6 @@ """Main Controller""" -from tg import expose, redirect, config, validate, override_template, response, render_template, tmpl_context +from tg import expose, redirect, config, validate, override_template, response, render_template, tmpl_context, i18n from tg.decorators import paginate, use_custom_format, with_trailing_slash, Decoration, before_render from tg.controllers import TGController from tg.validation import TGValidationError @@ -247,6 +247,20 @@ def jinja_filters(self): def jinja_buildins(self): return {} + @expose('jinja:jinja_i18n.jinja') + def jinja_i18n(self): + return {} + + @expose('jinja:jinja_i18n.jinja') + def jinja_i18n_en(self): + i18n.set_temporary_lang("en") + return {} + + @expose('jinja:jinja_i18n.jinja') + def jinja_i18n_de(self): + i18n.set_temporary_lang("de") + return {} + @expose('chameleon_genshi:index.html') def chameleon_genshi_index(self): return {} diff --git a/tests/test_stack/rendering/templates/jinja_i18n.jinja b/tests/test_stack/rendering/templates/jinja_i18n.jinja new file mode 100644 index 00000000..a9984fd4 --- /dev/null +++ b/tests/test_stack/rendering/templates/jinja_i18n.jinja @@ -0,0 +1 @@ +{% trans %}Your application is now running{% endtrans %} diff --git a/tests/test_stack/rendering/test_dotted_rendering.py b/tests/test_stack/rendering/test_dotted_rendering.py index 940fb5a8..b661f80f 100644 --- a/tests/test_stack/rendering/test_dotted_rendering.py +++ b/tests/test_stack/rendering/test_dotted_rendering.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from nose import SkipTest from tests.test_stack import TestConfig, app_from_config from tg.util import Bunch, no_warn @@ -49,6 +51,20 @@ def test_jinja_inherits_mixed(): resp = app.get('/jinja_inherits_mixed') assert "Welcome on my awsome homepage" in resp, resp +def test_jinja_i18n(): + app = setup_noDB() + resp = app.get('/jinja_i18n', status=200) + +def test_jinja_i18n_en(): + app = setup_noDB() + resp = app.get('/jinja_i18n_en') + assert "Your application is now running" in resp + +def test_jinja_i18n_de(): + app = setup_noDB() + resp = app.get('/jinja_i18n_de') + assert u"Ihre Anwendung läuft jetzt einwandfrei" in resp + def test_default_genshi_renderer(): app = setup_noDB() resp = app.get('/index_dotted') diff --git a/tg/configuration/app_config.py b/tg/configuration/app_config.py index 81dc8182..8f35c23c 100644 --- a/tg/configuration/app_config.py +++ b/tg/configuration/app_config.py @@ -8,7 +8,7 @@ import mimetypes from collections import MutableMapping as DictMixin -from tg.i18n import ugettext, get_lang +from tg.i18n import ugettext, ungettext, get_lang from tg.support.middlewares import SessionMiddleware, CacheMiddleware from tg.support.middlewares import StaticsMiddleware @@ -271,7 +271,7 @@ def init_config(self, global_conf, app_conf): self.package_name = self.package.__name__ except AttributeError: self.package_name = None - + log.debug("Initializing configuration, package: '%s'", self.package_name) conf = global_conf.copy() conf.update(app_conf) @@ -589,6 +589,10 @@ def setup_jinja_renderer(self): if not 'jinja_extensions' in self : self.jinja_extensions = [] + # Add i18n extension by default + if not "jinja2.ext.i18n" in self.jinja_extensions: + self.jinja_extensions.append("jinja2.ext.i18n") + if not 'jinja_filters' in self: self.jinja_filters = {} @@ -625,6 +629,9 @@ def setup_jinja_renderer(self): # Jinja's unable to request c's attributes without strict_c config['tg.strict_tmpl_context'] = True + # Add gettext functions to the jinja environment + config['tg.app_globals'].jinja2_env.install_gettext_callables(ugettext, ungettext) + self.render_functions.jinja = render_jinja def setup_amf_renderer(self): #pragma: no cover @@ -1137,7 +1144,7 @@ def make_base_app(global_conf=None, wrap_app=None, full_stack=False, **app_conf) if global_conf is None: global_conf = {} - + # Configure the Application environment if load_environment: load_environment(global_conf, app_conf)