views:

33

answers:

2

I am reading the Django localization documentation:http://docs.djangoproject.com/en/dev/topics/i18n/localization/

Of course, where the user is from determines what "message file" to use.

How do I determine where the user is from and what to use? Does it do it automatically?

+2  A: 

You can add Locale middleware to your MIDDLEWARE_CLASSES in settings if you want to enable language selection based on data from the request in Django.

Read how Django discovers language preference to learn details.

From docs

LocaleMiddleware tries to determine the user's language preference by following this algorithm:

  • First, it looks for a django_language key in the current user's session.

  • Failing that, it looks for a cookie.

  • Failing that, it looks at the Accept-Language HTTP header. This header is sent by your browser and tells the server which language(s) you prefer, in order by priority. Django tries each language in the header until it finds one with available translations.

  • Failing that, it uses the global LANGUAGE_CODE setting.

rebus
A: 

It determines the user's language from the browser's language settings. If it doesn't find that language in your messages files it will use the default one.

Seitaridis