diff options
author | Markus Heiser <markus.heiser@darmarit.de> | 2022-01-01 17:22:22 +0100 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarit.de> | 2022-01-01 17:31:38 +0100 |
commit | 8a07559ab54da64b916552ef59e86f5cceab623a (patch) | |
tree | 52d89f5d397e2fd14fe8aac08da97b1270e320ba /searxng_extra/update | |
parent | 61ce0c2244135e88c6c015ff29d5e896a49f46b6 (diff) | |
download | searxng-8a07559ab54da64b916552ef59e86f5cceab623a.tar.gz searxng-8a07559ab54da64b916552ef59e86f5cceab623a.zip |
[fix] update_languages.py: no excption on unknown locale & language
Fix exception handling of unknown locales and languages::
ERROR: ca_ES_valencia --> [Errno 2] No such file or directory: 'local/py3/lib/python3.8/site-packages/babel/locale-data/ca_ES_valencia.dat'
ERROR: languages['fil-PH'] --> {'name': None, 'english_name': None}
ERROR: languages['nb-NO'] --> {'name': None, 'english_name': None}
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searxng_extra/update')
-rwxr-xr-x | searxng_extra/update/update_languages.py | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/searxng_extra/update/update_languages.py b/searxng_extra/update/update_languages.py index 526469342..3a172d5dc 100755 --- a/searxng_extra/update/update_languages.py +++ b/searxng_extra/update/update_languages.py @@ -35,6 +35,8 @@ def fetch_supported_languages(): if type(engines_languages[engine_name]) == list: engines_languages[engine_name] = sorted(engines_languages[engine_name]) + print("fetched languages from %s engines" % len(engines_languages)) + # write json file with open(engines_languages_file, 'w', encoding='utf-8') as f: json.dump(engines_languages, f, indent=2, sort_keys=True) @@ -97,7 +99,11 @@ def join_language_lists(engines_languages): country_name = '' if locale: # get country name from babel's Locale object - country_name = locale.get_territory_name() + try: + country_name = locale.get_territory_name() + except FileNotFoundError as exc: + print("ERROR: %s --> %s" % (locale, exc)) + locale = None language_list[short_code]['countries'][lang_code] = {'country_name': country_name, 'counter': set()} @@ -186,17 +192,24 @@ def write_languages_file(languages): "language_codes =", ) - language_codes = tuple( - [ - ( - code, - languages[code]['name'].split(' (')[0], - languages[code].get('country_name') or '', - languages[code].get('english_name') or '', - ) - for code in sorted(languages) - ] - ) + language_codes = [] + + for code in sorted(languages): + + name = languages[code]['name'] + if name is None: + print("ERROR: languages['%s'] --> %s" % (code, languages[code])) + continue + item = ( + code, + languages[code]['name'].split(' (')[0], + languages[code].get('country_name') or '', + languages[code].get('english_name') or '', + ) + + language_codes.append(item) + + language_codes = tuple(language_codes) with open(languages_file, 'w') as new_file: file_content = "{file_headers} \\\n{language_codes}".format( |