Skip to content

i18n not working at all #22

Closed
packardb opened this Issue May 12, 2011 · 7 comments

2 participants

@packardb

System:

Darwin 10.7.0 Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386 i386

Packages: (with version)

Babel-0.9.6
Jinja2-2.5.5
pyramid_jinja2-0.6.2

development.ini:
...
default_locale_name = ro
jinja2.directories = templates
...

init.py:
...
config.include('pyramid_jinja2')
...

views.py: (later explanation)

def index(request):
print get_localizer(request).translate(_('Subscription form'))

templates/register.jinja2:
...
{% trans %}Subscription form{% endtrans %}
...

Issue:

When the index() function from views.py gets called, it prints the translated string (from locale/ro/LC_MESSAGES/...), however, when i render the template, 'Subscription form' doesn't get translated at all.

I also have added jinja2.ext.i18n to jinja2.extensions in development.ini, however, it still won't translate my strings.

What am i doing wrong?

@rockyburt
Pylons Project member

Well there's still some context missing, like are you using the same message domain in both raw code and the jinja2, etc. But regardless, I just committed a demo app that shows how to use i18n:
https://github.com/Pylons/pyramid_jinja2/tree/master/pyramid_jinja2/demo

To run the demo locally simply type:

python -m pyramid_jinja2.demo.__init__

The resulting web page will demonstrate translating english to french.

@rockyburt rockyburt closed this May 12, 2011
@packardb

I want to use the same message domain for both raw code and jinja2 (casting). Also, i use render_to_response() in my view to render the template however this doesn't seem to be the problem.

@rockyburt
Pylons Project member

As of pyramid_jinja2 0.6.2 the only domain checked during jinja2 rendering is "messages". So the real issue here is that you want to use a domain other than "messages" ?

@rockyburt rockyburt reopened this May 12, 2011
@packardb

This is bad, it's the only test i haven't done yet (using messages instead of my app's name as domain). I don't really mind using messages, but it would be nice if pyramid_jinja2 would somewhat "inherit" the domain from somewhere ... Until then, i'll use messages. It really sucks because setup.cfg is created with appname as message domain

@rockyburt
Pylons Project member

Ok so I just made some more commits for this stuff... it's now possible to override the default domain with the 'jinja2.i18n.domain'.
config = Configurator(settings={'jinja2.i18n.domain': 'myappname'})

I've also updated the paster template that comes with pyramid_jinja2 to setup the default domain to be the name of the app for use with jinja2 templates. Can you try latest git clone to see if it works for you?

@rockyburt
Pylons Project member

As soon as we close this issue I will be releasing a new version of pyramid_jinja2 so please confirm if the changes I made help you do what you need.

@rockyburt rockyburt closed this May 12, 2011
@rockyburt rockyburt reopened this May 12, 2011
@rockyburt rockyburt closed this May 12, 2011
@packardb

Seems to be working as expected. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.