I want to fetch default language of browser. I have tried some code for this but nothing works for me correctly .
I can get an array of all languages thhat are activated in browser from this request.META['HTTP_ACCEPT_LANGUAGE']
. But how I can get that language which is set as default .
Functions of particular interest are django. utils. translation. get_language() which returns the language used in the current thread.
This process relies on the GNU gettext toolset. Once this is done, Django takes care of translating web apps on the fly in each available language, according to users' language preferences.
add the middleware django.middleware.locale.LocaleMiddleware
in setting.py
following the middleware order as
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
# other middleware ...
)
and use request.LANGUAGE_CODE
to get the browser language.
source http://www.janosgyerik.com/
I used it to solve that problem in a project
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With