Be careful with the method you use to get the language . Depending on the method, Django will use different methods and information to determine the correct language to use.
When using the django.utils.translation.get_language() function, it is associated with the thread language. Prior to Django 1.8, it always returned settings.LANGUAGE_CODE when translations were disabled. If you want to manually redefine the language of the streams, you can use the override() or activate() functions, which are not explicitly specified explicitly, but well, still useful:
from django.utils import translation with translation.override('fr'): print(_("Hello"))
If you want django to check the path and / or request (language cookie, ...) , which is much more common, for example. www.example.com/en/<somepath> vs www.example.com/fr/<somepath> , use django.utils.translation.get_language_from_request(request, check_path=False) . In addition, it will always return a valid language in settings.LANGUAGES
It was not easy for me to find these differences through Google on this subject, so here for further links.
achedeuzot Nov 11 '15 at 11:04 2015-11-11 11:04
source share