From c937a9e85f510820f7d9b98666dcf83f72f80ceb Mon Sep 17 00:00:00 2001 From: Marc Abonce Seguin Date: Wed, 3 Feb 2021 01:02:21 -0700 Subject: [fix] get correct locale with country from browser Some of our interface locales include uppercase country codes, which are separated by `_` instead of the more common `-`. Also, a browser's `Accept-Language` header could be in lowercase. This commit attempts to normalize those cases so a browser's language+country codes can better match with our locales. This solution assumes that our UI locales have nothing more than language and optionally country. If we ever add a script specific locale like `zh-Hant-TW` this would have to change to accomodate that, but the idea would be pretty much the same as this fix. --- tests/unit/test_webapp.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/unit/test_webapp.py b/tests/unit/test_webapp.py index 32aa22fb5..a488faf58 100644 --- a/tests/unit/test_webapp.py +++ b/tests/unit/test_webapp.py @@ -198,6 +198,20 @@ class ViewsTestCase(SearxTestCase): result.data ) + def test_browser_locale(self): + result = self.app.get('/preferences', headers={'Accept-Language': 'zh-tw;q=0.8'}) + self.assertEqual(result.status_code, 200) + self.assertIn( + b'