Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/TurboGears/tg2 into …
Browse files Browse the repository at this point in the history
…development
  • Loading branch information
amol- committed Mar 4, 2013
2 parents b09a557 + 820ac35 commit 4cb0a14
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 4 deletions.
Binary file not shown.
19 changes: 19 additions & 0 deletions 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 <EMAIL@ADDRESS>\n"
"Language-Team: de <LL@li.org>\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"
16 changes: 15 additions & 1 deletion 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
Expand Down Expand Up @@ -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 {}
Expand Down
1 change: 1 addition & 0 deletions tests/test_stack/rendering/templates/jinja_i18n.jinja
@@ -0,0 +1 @@
{% trans %}Your application is now running{% endtrans %}
16 changes: 16 additions & 0 deletions 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
Expand Down Expand Up @@ -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')
Expand Down
13 changes: 10 additions & 3 deletions tg/configuration/app_config.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4cb0a14

Please sign in to comment.