I18n example #19

brutka opened this Issue Apr 6, 2011 · 5 comments

2 participants


I cannot get I18n working?
I need to add gettext calls to context globals.
There is no any example on the web of doing so.
I have ended up with:


jinja2_environment = registry.queryUtility(IJinja2Environment)
        lambda x: translations.ugettext(x),
        lambda s, p, n: translations.ungettext(s, p, n),

but it doesn't work as well.

Please, provide any sample of that.

Pylons Project member

Are you adding "jinja2.ext.i18n" to the list of jinja2 extensions via the "jinja2.extensions" setting? (you can add that using development.ini if you are using paste)

Pylons Project member

Well in any event, I went ahead and activated the i18n support in jinja2 (for pyramid_jinja2) by default. There's now a test (pyramid_jinja2/tests/test_ext.py) that shows using i18n... also there are docs now added. I just released this as 0.6.2 so please test with 0.6.2. If you still have trouble getting it working, please open a new issue.

@rockyburt rockyburt closed this Apr 6, 2011
Pylons Project member
  1. Create message catalogs
  2. Add the base directory of the message catalogs to Pyramid's config via http://docs.pylonsproject.org/projects/pyramid/1.0/api/config.html#pyramid.config.Configurator.add_translation_dirs

Once you do steps #1 and #2 then {% trans %}some string{% endtrans %} will work in jinja2 templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment