mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
parent
1ae7610622
commit
5075281add
@ -16,7 +16,11 @@ def preferred_regions(
|
|||||||
country: str | None = None,
|
country: str | None = None,
|
||||||
code: str | None = None,
|
code: str | None = None,
|
||||||
) -> Iterable[str | 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:
|
if country is not None:
|
||||||
yield country.upper()
|
yield country.upper()
|
||||||
|
|
||||||
@ -27,10 +31,8 @@ def preferred_regions(
|
|||||||
elif language == "zh":
|
elif language == "zh":
|
||||||
if code == "Hant":
|
if code == "Hant":
|
||||||
yield "HK"
|
yield "HK"
|
||||||
elif code == "Hans":
|
|
||||||
yield "TW"
|
yield "TW"
|
||||||
else:
|
else:
|
||||||
# Prefer China if no matching code
|
|
||||||
yield "CN"
|
yield "CN"
|
||||||
|
|
||||||
# fr -> fr-FR
|
# fr -> fr-FR
|
||||||
|
@ -95,31 +95,40 @@ def test_language_as_region() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_zh_hant() -> 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(
|
assert language.matches(
|
||||||
"zh-Hant",
|
"zh-Hant",
|
||||||
["en-US", "en-GB", "zh-CN", "zh-HK", "zh-TW"],
|
["en-US", "en-GB", "zh-CN", "zh-HK", "zh-TW"],
|
||||||
) == [
|
) == [
|
||||||
"zh-HK",
|
"zh-HK",
|
||||||
"zh-CN",
|
|
||||||
"zh-TW",
|
"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:
|
def test_zh_hans() -> None:
|
||||||
"""Test that the zh-Hans defaults to TW."""
|
"""Test that the zh-Hans matches CN first."""
|
||||||
assert language.matches(
|
assert language.matches(
|
||||||
"zh-Hans",
|
"zh-Hans",
|
||||||
["en-US", "en-GB", "zh-CN", "zh-HK", "zh-TW"],
|
["en-US", "en-GB", "zh-CN", "zh-HK", "zh-TW"],
|
||||||
) == [
|
) == [
|
||||||
"zh-TW",
|
|
||||||
"zh-CN",
|
"zh-CN",
|
||||||
"zh-HK",
|
"zh-HK",
|
||||||
|
"zh-TW",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def test_zh_no_code() -> None:
|
def test_zh_no_code() -> None:
|
||||||
"""Test that the zh defaults to CN."""
|
"""Test that the zh defaults to CN first."""
|
||||||
assert language.matches(
|
assert language.matches(
|
||||||
"zh",
|
"zh",
|
||||||
["en-US", "en-GB", "zh-CN", "zh-HK", "zh-TW"],
|
["en-US", "en-GB", "zh-CN", "zh-HK", "zh-TW"],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user