-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
gh-137729: Fix support for locales with @-modifiers #137253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
serhiy-storchaka
merged 8 commits into
python:main
from
serhiy-storchaka:locale-modifiers
Aug 18, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
853cfbd
gh-87281: Fix support for locales with modifiers
serhiy-storchaka abcbb93
Skip the crashing tests on Windows.
serhiy-storchaka e0df7e0
Revert "Skip the crashing tests on Windows."
serhiy-storchaka 1e65e5b
Merge branch 'main' into locale-modifiers
serhiy-storchaka 4954f97
Add cocumentation.
serhiy-storchaka 1096f32
Add comments.
serhiy-storchaka 073572e
Fix typos.
serhiy-storchaka 8aaf1e7
Merge branch 'main' into locale-modifiers
serhiy-storchaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Misc/NEWS.d/next/Library/2025-08-14-00-00-12.gh-issue-137729.i9NSKP.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:func:`locale.setlocale` now supports language codes with ``@``-modifiers. | ||
``@``-modifier are no longer silently removed in :func:`locale.getlocale`, | ||
but included in the language code. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,13 +44,24 @@ def parse(filename): | |
# Ignore one letter locale mappings (except for 'c') | ||
if len(locale) == 1 and locale != 'c': | ||
continue | ||
if '@' in locale and '@' not in alias: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a comment explaining why this is done (to make glibc on Linux happy) |
||
# Do not simply remove the "@euro" modifier. | ||
# Glibc generates separate locales with the "@euro" modifier, and | ||
# not always generates a locale without it with the same encoding. | ||
# It can also affect collation. | ||
if locale.endswith('@euro') and not locale.endswith('.utf-8@euro'): | ||
alias += '@euro' | ||
# Normalize encoding, if given | ||
if '.' in locale: | ||
lang, encoding = locale.split('.')[:2] | ||
encoding = encoding.replace('-', '') | ||
encoding = encoding.replace('_', '') | ||
locale = lang + '.' + encoding | ||
data[locale] = alias | ||
# Conflict with glibc. | ||
data.pop('el_gr@euro', None) | ||
data.pop('uz_uz@cyrillic', None) | ||
data.pop('uz_uz.utf8@cyrillic', None) | ||
return data | ||
|
||
def parse_glibc_supported(filename): | ||
|
@@ -81,7 +92,7 @@ def parse_glibc_supported(filename): | |
# Add an encoding to alias | ||
alias, _, modifier = alias.partition('@') | ||
alias = _locale._replace_encoding(alias, alias_encoding) | ||
if modifier and not (modifier == 'euro' and alias_encoding == 'ISO-8859-15'): | ||
if modifier: | ||
alias += '@' + modifier | ||
data[locale] = alias | ||
return data | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment to this section stating that Linux appears to require keeping the "@euro" modifier in place, even when using the ".ISO8859-15" encoding.