Skip to content

Support locales with @-modifiers #137729

Description

@serhiy-storchaka

Feature or enhancement

Currently, locale.getlocale() does not support locales with @-modifiers. If the current locale has an @-modifier, it will be silently dropped in the locale.getlocale() result. For example, ca_ES.utf8@valencia will result in ('ca_ES', 'UTF-8'), sr_RS.utf8@latin -- ('sr_RS', 'UTF-8'), uz_UZ.utf8@cyrillic -- ('uz_UZ', 'UTF-8'). They are different locales! The @euro modifier, the only one that handled specially, is also removed, even if locales with and without @euro can be different locales, and @euro affects collation in some locales. And for the el_gr@euro locale it returns wrong encoding ISO8859-15 (the correct encoding for this locale on Linux is ISO8859-7).

Accordingly, locale.setlocale() does not support @-modifiers if the locale is specified as a language code/encoding pair. It is supported if specify locale as string, but then the purpose of the wrapper is lost.

See also #87281.

The only way to support @-modifiers in the format compatible with this functions is to include it in the language code. So locale.getlocale() will return ('ca_ES@valencia', 'UTF-8') for locale ca_ES.utf8@valencia, and passing ('ca_ES@valencia', 'UTF-8') to locale.setlocale() will set locale to ca_ES.utf8@valencia. This is mildly breaking change, but it is better to get error in program that do not expect @ in the locale.getlocale() result than get a wrong result for that locale.

Linked PRs

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

3.15pre-release feature fixes, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions