Closed Bug 808580 Opened 12 years ago Closed 12 years ago

Trans blocks loose translations after second reload

Categories

(www.mozilla.org :: Bedrock, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: rik, Unassigned)

References

(Blocks 1 open bug)

Details

Steps to reproduce: 1. Launch your server 2. Go to http://localhost:8000/de/foundation/annualreport/2011/ 3. Refresh Expected result: First paragragh says "Mozillas Vision des Internets ist ein Ort" etc. Actual result: First paragragh says "Mozilla‘s vision of the Internet" etc.
Summary: Trans blocks loose translations after .lang file is updated → Trans blocks loose translations after second reload
I can confirm that this behaviour only happens with {% trans %} blocks and not with _()
Setting cache_size to 0 in the jinja config does not change this. On the second load, dotlang.translate() is not called. We don't know why yet.
In my testing, jinja2.ext.InternationalizationExtension.parse returns the same thing after first and second run: MarkSafeIfAutoescape(expr=Call(node=Name(name='gettext', ctx='load'), args=[Const(value=u'In less than 20 years the Internet has changed our lives. It is a powerful platform with unprecedented opportunity and connectedness. But even with great growth and innovation there are significant challenges to this vision of a healthy Internet.')], kwargs=[], dyn_args=None, dyn_kwargs=None))
So by commenting l10n_utils.helpers.gettext, I don't see the translation on the firstrun. I think we should now look into install_gettext_translations or install_gettext_callables (http://jinja.pocoo.org/docs/extensions/#environment-methods) to register properly and get called everytime.
registering functions via `install_gettext_callables` does nothing to solve the issue, but does result in all translated text reverting to english on reload, including calls to `_()`. Somehow registering these functions with the environment and i18n extension causes them to be called only on the first run. I've tested with the test client in the shell and seen the same result. Even calling `jinja2.utils.clear_caches` between calls, which should clear all in memory caches, didn't help. My theory at this point is that something in Jinja2 or Django is causing our registered gettext functions to be overridden by the builtin gettext functions, making ours only be called the first time, and subsequent calls appear to be noop.
FOUND IT!! https://github.com/clouserw/tower/blob/master/tower/__init__.py#L86 Tower resets the gettext functions to its own every time `activate` is called :( It's late now. But at least we know what it is and should have a fix tomorrow.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
This has been pushed to production.
You need to log in before you can comment on or make changes to this bug.