Search code examples
pythondjangointernationalizationdjango-i18n

How to maintain different country versions of same language in Django?


I would like to have a few different versions of the same language in Django, customized for different countries (e.g. locale/en, locale/en_CA, locale/en_US, etc.). If there is no language for specific country I would expect to use the default language version (locale/en)).

Then in the settings file for each site I specify LANGUAGE_CODE and LANGUAGES.

For some reason, even if I specify the following settings, the locale/en_US translations are still used:

LANGUAGE_CODE = 'en'
LANGUAGES = (
    ('en', ugettext('English')),
)

Though I clearly specify that the language code should be en (not en-us).

Am I missing something? Already tried to find the answer in multiple places, including Django documentation.


Solution

  • A workaround to the issue would be to add following snippet to your settings.py file.

    import locale
    locale.locale_alias.pop('en', None)
    

    Special credit to Venelin Stoykov who was able to investigate the behavior of the Python locale module.