summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fatcat_scholar/hacks.py3
-rw-r--r--tests/test_web.py4
2 files changed, 6 insertions, 1 deletions
diff --git a/fatcat_scholar/hacks.py b/fatcat_scholar/hacks.py
index 96226ff..5cb8572 100644
--- a/fatcat_scholar/hacks.py
+++ b/fatcat_scholar/hacks.py
@@ -60,7 +60,7 @@ def parse_accept_lang(header: str, options: typing.List[str]) -> typing.Optional
"""
if not header:
return None
- chunks = [v.split(";")[0].split("-")[0] for v in header.split(",")]
+ chunks = [v.split(";")[0].split("-")[0].split("_")[0] for v in header.split(",")]
for c in chunks:
if len(c) == 2 and c in options:
return c
@@ -72,6 +72,7 @@ def test_parse_accept_lang() -> None:
assert parse_accept_lang("en,de", []) == None
assert parse_accept_lang("en,de", ["en"]) == "en"
assert parse_accept_lang("en-GB,de", ["en"]) == "en"
+ assert parse_accept_lang("zh_Hans_CN", ["en", "zh"]) == "zh"
assert parse_accept_lang("en,de", ["de"]) == "de"
assert (
parse_accept_lang("en-ca,en;q=0.8,en-us;q=0.6,de-de;q=0.4,de;q=0.2", ["de"])
diff --git a/tests/test_web.py b/tests/test_web.py
index b3e99a1..a5629e0 100644
--- a/tests/test_web.py
+++ b/tests/test_web.py
@@ -25,6 +25,10 @@ def test_main_view(client: Any) -> None:
assert resp.status_code == 200
assert "معلومات عن" in resp.content.decode("utf-8")
+ resp = client.get("/", headers={"Accept-Language": "zh_Hans_CN"})
+ assert resp.status_code == 200
+ assert "我们是" in resp.content.decode("utf-8")
+
def test_basic_api(client: Any) -> None:
"""