Reputation: 941
I am having trouble making django.middleware.locale.LocaleMiddleware
set Chinese language as per the cookies/header I specify in the request.
After some debugging, I have narrowed it down to the the following function, which rejects it
django.utils.translations.trans_real.check_for_language
all_locale_paths
returns only django's locales, which do not contain 'cn'. My apps are packaged and installed separately from the project itself, and they provide their own 'cn' language files, which get discovered successfully, but since their locale directories are not specified in LOCALE_PATHS
, the middleware does not check them.
What is the best approach to avoid this problem? I am not adding the LOCALE_PATHS
, as the app locations differ based on the different environments the project is deployed. I could import the app, and find the paths from it, but that seems like an overkill.
Upvotes: 0
Views: 154
Reputation: 20702
Django uses ISO-639 language codes (not country codes), which is also what browsers use in their Accept-Language
headers.
The language code for Chinese is "zh", in Django both variants "zh_Hans" and "zh_Hant" are supported. "cn" isn't a language code for Chinese.
Upvotes: 1