summaryrefslogtreecommitdiffstats
path: root/fatcat_scholar
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2020-10-28 15:52:42 -0700
committerBryan Newbold <bnewbold@archive.org>2020-10-28 15:52:45 -0700
commitf2157215e23fcb6583d090faf8cff49e9e6a7b12 (patch)
tree3fd97bdf1a34442daa70e6a55167580ff2f2c72e /fatcat_scholar
parent00e99192e7f746d7739adfe031b72bd7b0fee1a6 (diff)
downloadfatcat-scholar-f2157215e23fcb6583d090faf8cff49e9e6a7b12.tar.gz
fatcat-scholar-f2157215e23fcb6583d090faf8cff49e9e6a7b12.zip
web: fix lang detection (include 'en')
If a user had any non-english language preference, was defaulting to that, even if 'en' had higher preference.
Diffstat (limited to 'fatcat_scholar')
-rw-r--r--fatcat_scholar/hacks.py10
-rw-r--r--fatcat_scholar/web.py2
2 files changed, 11 insertions, 1 deletions
diff --git a/fatcat_scholar/hacks.py b/fatcat_scholar/hacks.py
index fc16564..96226ff 100644
--- a/fatcat_scholar/hacks.py
+++ b/fatcat_scholar/hacks.py
@@ -77,3 +77,13 @@ def test_parse_accept_lang() -> None:
parse_accept_lang("en-ca,en;q=0.8,en-us;q=0.6,de-de;q=0.4,de;q=0.2", ["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", ["en", "de"]
+ )
+ == "en"
+ )
+ assert (
+ parse_accept_lang("en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7", ["zh", "en", "de"])
+ == "en"
+ )
diff --git a/fatcat_scholar/web.py b/fatcat_scholar/web.py
index 79b4f30..2e7359b 100644
--- a/fatcat_scholar/web.py
+++ b/fatcat_scholar/web.py
@@ -43,7 +43,7 @@ class LangPrefix:
# first try to parse a language code from header
try:
accept_code = parse_accept_lang(
- request.headers.get("accept-language", ""), I18N_LANG_TRANSLATIONS,
+ request.headers.get("accept-language", ""), I18N_LANG_OPTIONS,
)
if accept_code:
self.code = accept_code