summaryrefslogtreecommitdiff
path: root/utils/fetch_languages.py
diff options
context:
space:
mode:
authorMarc Abonce Seguin <marc-abonce@mailbox.org>2018-02-28 22:30:48 -0600
committerMarc Abonce Seguin <marc-abonce@mailbox.org>2018-03-27 00:08:03 -0600
commit772c048d01c7585fd60afca1ce30a1914e6e5b4a (patch)
tree96a5662897df2bcf0ab53456e0a67ace998f2169 /utils/fetch_languages.py
parentd1eae9359f8c5920632a730744ea2208070f06da (diff)
downloadsearxng-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 'utils/fetch_languages.py')
-rw-r--r--utils/fetch_languages.py18
1 files changed, 3 insertions, 15 deletions
diff --git a/utils/fetch_languages.py b/utils/fetch_languages.py
index 4aabf68bf..dd7aa659f 100644
--- a/utils/fetch_languages.py
+++ b/utils/fetch_languages.py
@@ -19,19 +19,6 @@ from searx.engines import initialize_engines, engines
engines_languages_file = 'engines_languages.json'
languages_file = 'languages.py'
-# custom fixes for non standard locale codes
-# sl-SL is technically not invalid, but still a mistake
-# TODO: move to respective engines
-locale_fixes = {
- 'sl-sl': 'sl-SI',
- 'ar-xa': 'ar-SA',
- 'es-xl': 'es-419',
- 'zh-chs': 'zh-Hans-CN',
- 'zh-cht': 'zh-Hant-TW',
- 'tzh-tw': 'zh-Hant-TW',
- 'tzh-hk': 'zh-Hant-HK'
-}
-
# Fetchs supported languages for each engine and writes json file with those.
def fetch_supported_languages():
@@ -76,8 +63,9 @@ def join_language_lists(engines_languages):
for lang_code in engines_languages[engine_name]:
# apply custom fixes if necessary
- if lang_code.lower() in locale_fixes:
- lang_code = locale_fixes[lang_code.lower()]
+ if lang_code in getattr(engines[engine_name], 'language_aliases', {}).values():
+ lang_code = next(lc for lc, alias in engines[engine_name].language_aliases.items()
+ if lang_code == alias)
locale = get_locale(lang_code)