django.utils.translation.get_language()
returns default locale if translation is not activated. Is there a way to find out whether the translation is activated (via translation.activate()
) or not?
views:
154answers:
3
A:
Always inspect source code for such question, it's faster than posting to Web!
Django does it's black magic behind the scene, and uses some kind of dispatcher to simulate disabled translations.
The best way for you to do is:
import setttings
assert settings.USE_i18N == True
iElectric
2009-11-08 15:59:48
Always make sure you understand the question before posting an answer. I'm asking whether or not `translation.activate()` has been called.
muhuk
2009-11-09 17:44:15
Also you shouldn't import settings directly. Preferred way is `from django.conf import settings`, see docs for more information. Please correct your code.
muhuk
2009-11-09 17:45:06
+2
A:
Horribly hacky, but should work in at least 1.1.1:
import django.utils.translation.trans_real as trans
from django.utils.thread_support import currentThread
def isactive():
return currentThread() in trans._active
Ignacio Vazquez-Abrams
2010-03-15 20:22:18
A:
Depends on application and architecture...
Hack provided by Ignacio should works, but what is you will run in non activated yet thread?
I would use Ignacio solution + add Queue visible by all threads, monkeypatch trans_real.activate function and set attribute in queue.
bluszcz
2010-03-15 20:31:13