> As I mentioned in my other post, it doesn't work for the one process.
My previous code snippet missed an important statement. You will need
to first get an instance of _transactions from trans_real.py before
you declare it to be global. So, check if something like this helps:
from django.utils import translation
translation.deactivate_all()
_translations = translation.trans_real._translations # <--- Note this
globals _translations
_translations = {}
from datetime import datetime
globals _translations_loadtime
_translations_loadtime = datetime.now()
translation.activate(<translation language >)
>
> I don't know if I really need to bother with the timestamp as you
> outline below. I want the message files reloaded no matter what
> whenever someone submits new translations using my app.
In a production setting, you might have Django running under multiple
long running processes (each servicing an HTTP request at a time.)
Each of these processes has its own instance of the _translations
dictionary in question. So resetting it in one process won't be
sufficient. You need to somehow indicate to all processes that the
catalog needs to be reloaded. You could reload the catalog every time
by clearing out _translations on every request, but that's going to
affect performance. It's not optimal because you would only want a
reload when a translation has changed and a given process has not yet
loaded this changed translation. That's why I was suggesting the
timestamp approach (I am sure there are other ways to achieve that.)
>
> I'm probably understanding Python's 'global' declaration imperfectly,
> but from the print statements I have littered about in both my code
> and Django's, the _translations object I'm referring to in my view
> code doesn't seem to be the same object being referred to in
> trans_real.py.
It should be since you've i18n enabled. Django uses a nifty lazy
loading mechanism that dynamically switches between two different
implementations (trans_real and trans_null) depending on whether
you've i18n activated in your settings or not. See __init__.py in
django.utils.translation.
James Bennett has a nice article about server startup in which one
section talks about registries. It might be worth it to peruse that
even though it doesn't directly address this problem.
See:
http://www.b-list.org/weblog/2007/nov/05/server-startup/
-Rajesh