New submission from Serhiy Storchaka: >>> import locale, _locale >>> _locale.setlocale(locale.LC_CTYPE, 'en_AG') 'en_AG' >>> _locale.setlocale(locale.LC_CTYPE) 'en_AG' >>> locale.getlocale(locale.LC_CTYPE) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/serhiy/py/cpython/Lib/locale.py", line 575, in getlocale return _parse_localename(localename) File "/home/serhiy/py/cpython/Lib/locale.py", line 484, in _parse_localename raise ValueError('unknown locale: %s' % localename) ValueError: unknown locale: en_AG
One solution is proposed in issue20079: map all supported in glibc locale names without encoding to locale names with encoding. But see issue20087. And default encoding can be different on other systems (not based on glibc). Other solution is not guess an encoding, but use locale.nl_langinfo(locale.CODESET) in locale.getlocale(). And left in locale alias table only nonstandard mappings (such as english_uk -> en_GB.ISO8859-1 and sr_yu.iso88595 -> sr_CS.ISO8859-5). ---------- components: Library (Lib) messages: 207026 nosy: lemburg, loewis, serhiy.storchaka priority: normal severity: normal status: open title: locale.getlocale() fails if locale name doesn't include encoding type: behavior versions: Python 2.7, Python 3.3, Python 3.4 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue20088> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com