如何在Django中维护相同语言的不同国家/地区版本? [英] How to maintain different country versions of same language in Django?

查看:79
本文介绍了如何在Django中维护相同语言的不同国家/地区版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Django中使用相同语言的几种不同版本,针对不同国家/地区进行自定义(例如locale/enlocale/en_CAlocale/en_US等).如果没有特定国家/地区的语言,我希望使用默认语言版本(locale/en)).

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)).

然后在每个站点的设置文件中,我指定LANGUAGE_CODELANGUAGES.

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

由于某些原因,即使我指定了以下设置,仍会使用locale/en_US转换:

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')),
)

尽管我明确指定语言代码应为en(而不是en-us).

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

我错过了什么吗?已经尝试在多个地方找到答案,包括Django文档.

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

推荐答案

该问题的一种解决方法是将以下代码段添加到您的settings.py文件中.

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

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

特别感谢Venelin Stoykov,他能够研究Python locale模块的行为.

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

这篇关于如何在Django中维护相同语言的不同国家/地区版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆