[Django]-How to prioritize internationalization parameters


If you have a saved preference somewhere, then that would be the first choice.

The cookie value is, presumably, what they chose last time they were around so that would be the first thing to check.

The hl parameter is something that Google has figured out and they probably know what they’re doing so that seems like a sensible third choice.

Then we have the HTTP headers or a final default so check the accept language header next. And finally, have a default language in place just in case all else fails.

So, in order:

  1. Saved preference.
  2. Cookie.
  3. hl parameter.
  4. HTTP accept language header.
  5. Built in default.

Ideally you’d backtrack up the list once you get a language from somewhere so that you’d have less work to do on the next request. For example, if you ended up getting the language from the accept language header, you’d want to: set hl (possibly redirecting), store it in the cookie, and save the preference in their user settings (if you have such a permanent store and a signed in person).

Leave a comment