mirror of
https://github.com/searxng/searxng.git
synced 2024-11-22 12:10:11 +01:00
[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>
This commit is contained in:
parent
61ce0c2244
commit
8a07559ab5
@ -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
|
||||
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(
|
||||
[
|
||||
(
|
||||
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 '',
|
||||
)
|
||||
for code in sorted(languages)
|
||||
]
|
||||
)
|
||||
|
||||
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(
|
||||
|
Loading…
Reference in New Issue
Block a user