-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
Support locales with @-modifiers #137729
Copy link
Copy link
Closed
Labels
3.15new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Metadata
Metadata
Assignees
Labels
3.15new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Projects
Status
Done
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 thelocale.getlocale()result. For example,ca_ES.utf8@valenciawill 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@euromodifier, the only one that handled specially, is also removed, even if locales with and without@eurocan be different locales, and@euroaffects collation in some locales. And for theel_gr@eurolocale 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. Solocale.getlocale()will return('ca_ES@valencia', 'UTF-8')for localeca_ES.utf8@valencia, and passing('ca_ES@valencia', 'UTF-8')tolocale.setlocale()will set locale toca_ES.utf8@valencia. This is mildly breaking change, but it is better to get error in program that do not expect@in thelocale.getlocale()result than get a wrong result for that locale.Linked PRs