I'm developing a multilingual Django website. It has two languages, English and Hebrew. I want the default languag开发者_运维百科e for every first-time visitor to be Hebrew, regardless of what his browser's Accept-Language
is.
Of course, if he changes language to English (and thus gets the language cookie or the key in the session), it should remain at English.
I think I can program this algorithm myself, but where do I "plug it in"? How do I make my project use it?
Maybe you don't have to override anything. You can just check on the first page, (or maybe every page) if the user already has a language cookie and otherwise redirect him to the set_language redirect view. In that way you could force the language to Hebrew.
If the user decides to change back to English, he can do it very easily.
Start by reading this: http://docs.djangoproject.com/en/1.1/topics/i18n/#topics-i18n
Then read this: http://docs.djangoproject.com/en/1.1/topics/i18n/internationalization/#topics-i18n-internationalization
Each RequestContext has access to three translation-specific variables:
LANGUAGES is a list of tuples in which the first element is the language code and the second is the language name (translated into the currently active locale).
LANGUAGE_CODE is the current user's preferred language, as a string. Example: en-us. (See How Django discovers language preference.)
LANGUAGE_BIDI is the current locale's direction. If True, it's a right-to-left language, e.g.: Hebrew, Arabic. If False it's a left-to-right language, e.g.: English, French, German etc.
If you don't use the RequestContext extension, you can get those values with three tags:
Is this what you're asking about?
精彩评论