How can I list all available windows locales in py

2019-01-24 00:07发布

On linux we can use locale -a to see the list of locales available.

$ locale -a
C
C.UTF-8
en_US.utf8
POSIX 

Is it possible to do the same from python console on windows?

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.

标签: python locale
3条回答
做自己的国王
2楼-- · 2019-01-24 00:20
>>> import locale
>>> locale.locale_alias
查看更多
仙女界的扛把子
3楼-- · 2019-01-24 00:25

the richest locale support i found in python is 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.

hth, alex

查看更多
唯我独甜
4楼-- · 2019-01-24 00:32

You can look up available locale names on 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.

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',
}
查看更多
登录 后发表回答