diff --git a/babel/core.py b/babel/core.py index 3ba8b85ea..d173e4863 100644 --- a/babel/core.py +++ b/babel/core.py @@ -361,6 +361,12 @@ def parse( if not isinstance(identifier, str): raise TypeError(f"Unexpected value for identifier: {identifier!r}") + # C/POSIX is not a CLDR language. Same mapping default_locale uses. + posix_stem = identifier.split(".")[0].split("@")[0] + posix_stem = posix_stem.replace("-", "_") + if posix_stem.upper() in {"C", "POSIX"}: + identifier = "en_US_POSIX" + parts = parse_locale(identifier, sep=sep) input_id = get_locale_identifier(parts) diff --git a/tests/test_core.py b/tests/test_core.py index 2c1e6d92e..445ed67a8 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -56,6 +56,12 @@ def test_default_locale(monkeypatch): assert default_locale() == 'en_US_POSIX' +def test_locale_parse_accepts_c_and_posix(): + expected = Locale.parse('en_US_POSIX') + for value in ['C', 'c', 'POSIX', 'posix', 'C.UTF-8', 'C.utf8', 'POSIX.UTF-8']: + assert Locale.parse(value) == expected + + def test_default_locale_multiple_args(monkeypatch): for name in [ 'LANGUAGE',