如何在 python 控制台中列出所有可用的 Windows 语言环境?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19709026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I list all available windows locales in python console?
提问by minerals
On linux we can use locale -a
to see the list of locales available.
在 linux 上,我们可以locale -a
用来查看可用的语言环境列表。
$ locale -a
C
C.UTF-8
en_US.utf8
POSIX
Is it possible to do the same from python console on windows?
是否可以从Windows上的 python 控制台执行相同操作?
This can be handy when you try to do locale.setlocale(locale.LC_ALL, '???')
and simply don't know the name of the locale value.
当您尝试这样做locale.setlocale(locale.LC_ALL, '???')
并且根本不知道语言环境值的名称时,这会很方便。
采纳答案by devnull
>>> import locale
>>> locale.locale_alias
回答by schlamar
You can look up available locale names on MSDN.
您可以在MSDN上查找可用的语言环境名称。
You have to pass the long version from "Language string" in the MSDN list as value to setlocale
. The default L10N short codes like en_EN
which are in locale_alias
do NOT work in general.
您必须将 MSDN 列表中“语言字符串”中的长版本作为值传递给setlocale
. 默认的本地化短代码就像en_EN
它们是locale_alias
不工作的总称。
I have already extracted some of them as dictionary:
我已经将其中一些提取为字典:
LANGUAGES = {
'bg_BG': 'Bulgarian',
'cs_CZ': 'Czech',
'da_DK': 'Danish',
'de_DE': 'German',
'el_GR': 'Greek',
'en_US': 'English',
'es_ES': 'Spanish',
'et_EE': 'Estonian',
'fi_FI': 'Finnish',
'fr_FR': 'French',
'hr_HR': 'Croatian',
'hu_HU': 'Hungarian',
'it_IT': 'Italian',
'lt_LT': 'Lithuanian',
'lv_LV': 'Latvian',
'nl_NL': 'Dutch',
'no_NO': 'Norwegian',
'pl_PL': 'Polish',
'pt_PT': 'Portuguese',
'ro_RO': 'Romanian',
'ru_RU': 'Russian',
'sk_SK': 'Slovak',
'sl_SI': 'Slovenian',
'sv_SE': 'Swedish',
'tr_TR': 'Turkish',
'zh_CN': 'Chinese',
}
回答by undisclosed
the richest locale support i found in python is babel.
我在 python 中找到的最丰富的语言环境支持是 babel。
please install by:
请通过以下方式安装:
pip install babel
then,
然后,
import babel
all_ids = babel.localedata.locale_identifiers()
there is also extensive support for common terms translation etc. babel is being used in various other packages.
还有对常用术语翻译等的广泛支持。 babel 正被用于各种其他软件包。
hth, alex
嗯,亚历克斯