parent
1ae7610622
commit
5075281add
|
@ -16,7 +16,11 @@ def preferred_regions(
|
|||
country: str | None = None,
|
||||
code: str | None = None,
|
||||
) -> Iterable[str | None]:
|
||||
"""Yield preferred regions for a language based on country/code hints."""
|
||||
"""Yield an ordered list of regions for a language based on country/code hints.
|
||||
|
||||
Regions should be checked for support in the returned order if no other
|
||||
information is available.
|
||||
"""
|
||||
if country is not None:
|
||||
yield country.upper()
|
||||
|
||||
|
@ -27,10 +31,8 @@ def preferred_regions(
|
|||
elif language == "zh":
|
||||
if code == "Hant":
|
||||
yield "HK"
|
||||
elif code == "Hans":
|
||||
yield "TW"
|
||||
else:
|
||||
# Prefer China if no matching code
|
||||
yield "CN"
|
||||
|
||||
# fr -> fr-FR
|
||||
|
|
|
@ -95,31 +95,40 @@ def test_language_as_region() -> None:
|
|||
|
||||
|
||||
def test_zh_hant() -> None:
|
||||
"""Test that the zh-Hant defaults to HK."""
|
||||
"""Test that the zh-Hant matches HK or TW first."""
|
||||
assert language.matches(
|
||||
"zh-Hant",
|
||||
["en-US", "en-GB", "zh-CN", "zh-HK", "zh-TW"],
|
||||
) == [
|
||||
"zh-HK",
|
||||
"zh-CN",
|
||||
"zh-TW",
|
||||
"zh-CN",
|
||||
]
|
||||
|
||||
assert language.matches(
|
||||
"zh-Hant",
|
||||
["en-US", "en-GB", "zh-CN", "zh-TW", "zh-HK"],
|
||||
) == [
|
||||
"zh-TW",
|
||||
"zh-HK",
|
||||
"zh-CN",
|
||||
]
|
||||
|
||||
|
||||
def test_zh_hans() -> None:
|
||||
"""Test that the zh-Hans defaults to TW."""
|
||||
"""Test that the zh-Hans matches CN first."""
|
||||
assert language.matches(
|
||||
"zh-Hans",
|
||||
["en-US", "en-GB", "zh-CN", "zh-HK", "zh-TW"],
|
||||
) == [
|
||||
"zh-TW",
|
||||
"zh-CN",
|
||||
"zh-HK",
|
||||
"zh-TW",
|
||||
]
|
||||
|
||||
|
||||
def test_zh_no_code() -> None:
|
||||
"""Test that the zh defaults to CN."""
|
||||
"""Test that the zh defaults to CN first."""
|
||||
assert language.matches(
|
||||
"zh",
|
||||
["en-US", "en-GB", "zh-CN", "zh-HK", "zh-TW"],
|
||||
|
|
Loading…
Reference in New Issue