diff options
author | Marc Abonce Seguin <marc-abonce@mailbox.org> | 2018-02-28 22:30:48 -0600 |
---|---|---|
committer | Marc Abonce Seguin <marc-abonce@mailbox.org> | 2018-03-27 00:08:03 -0600 |
commit | 772c048d01c7585fd60afca1ce30a1914e6e5b4a (patch) | |
tree | 96a5662897df2bcf0ab53456e0a67ace998f2169 /searx/query.py | |
parent | d1eae9359f8c5920632a730744ea2208070f06da (diff) | |
download | searxng-772c048d01c7585fd60afca1ce30a1914e6e5b4a.tar.gz searxng-772c048d01c7585fd60afca1ce30a1914e6e5b4a.zip |
refactor engine's search language handling
Add match_language function in utils to match any user given
language code with a list of engine's supported languages.
Also add language_aliases dict on each engine to translate
standard language codes into the custom codes used by the engine.
Diffstat (limited to 'searx/query.py')
-rw-r--r-- | searx/query.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/searx/query.py b/searx/query.py index 6e5f2e883..6076c2d75 100644 --- a/searx/query.py +++ b/searx/query.py @@ -96,9 +96,13 @@ class RawTextQuery(object): break # user may set a valid, yet not selectable language - if not self.languages and VALID_LANGUAGE_CODE.match(lang): - self.languages.append(lang) - parse_next = True + if VALID_LANGUAGE_CODE.match(lang): + lang_parts = lang.split('-') + if len(lang_parts) > 1: + lang = lang_parts[0].lower() + '-' + lang_parts[1].upper() + if lang not in self.languages: + self.languages.append(lang) + parse_next = True # this force a engine or category if query_part[0] == '!' or query_part[0] == '?': |