Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translations don't work #30

Open
martinsvoboda opened this issue Jan 6, 2013 · 8 comments
Open

Translations don't work #30

martinsvoboda opened this issue Jan 6, 2013 · 8 comments

Comments

@martinsvoboda
Copy link

Hi,
jingo without any extra configuration doesn't translate texts in templates. In documentation isn't any notice about this behaviour. Issue arise because jingo in default config install null translation in jinja2 enviroment (https://github.com/jbalogh/jingo/blob/master/jingo/__init__.py#L70).

For resolving issue you must install gettext translation:

from django.utils import translation
from jingo import env
env.install_gettext_translations(translation)

Comment before install_null_translations() says that call is important for testing, so we should choose cautious solution. May be create some optional setting for these cases and definitely write down documentation.

@gandriyko
Copy link

Yes, I wrote the same. All works fine if run as "manage.py runserver".
But if run project via uwsgi, raised following exception:

   File "/home/shop/shop/settings.py", line 295, in <module>
    jingo.env.install_gettext_translations(translation)
AttributeError: 'module' object has no attribute 'env'

But project running and works.

@martinsvoboda
Copy link
Author

I work around this. I have gettext installation in the file of my private app jingoi18n/init.py
But for correct working it needs calling of admin.autodiscover() in urls.py of project. I think it's possible move instalation code to settings.py and it will works.

@gandriyko
Copy link

I try putting initialization code in settings.py already, same exception.

@jsocol
Copy link
Collaborator

jsocol commented Feb 13, 2013

It looks like that exception has to do with jingo not being imported correctly before running jingo.env.install_gettext_translations(). The env object is created as an import-time side-effect of the jingo module. (Not a great way to do it, admittedly.)

runserver imports everything in INSTALLED_APPS when it runs model verification, so it works then. I'm guessing uwsgi doesn't have that init step. I've seen similar things with gunicorn and Raven, where I had to add a process start up hook to get the import-time side-effects.

How are you importing jingo in settings.py?

@gandriyko
Copy link

setttings.py:

import jingo.monkey
jingo.monkey.patch()

try:
    from django.utils import translation
    from jingo.import env
    env.install_gettext_translations(translation)
except:
    pass

@jsocol
Copy link
Collaborator

jsocol commented Feb 13, 2013

env isn't a module, but monkey is. Try replacing the second import in the try: block with:

import jingo
jingo.env.install_gettext_translations(translation)

@gandriyko
Copy link

Just tried. Same errror:

jingo.env.install_gettext_translations(translation)
AttributeError: 'module' object has no attribute 'env'

@jsocol
Copy link
Collaborator

jsocol commented Oct 23, 2015

Can anyone who ran into this try with Jingo 0.8? There are some changes (there's no jingo.env anymore, but jingo.get_env() will return the instance) but the upgrade shouldn't be too rough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants