[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:
Markus Heiser 2022-01-01 17:22:22 +01:00
parent 61ce0c2244
commit 8a07559ab5

View file

@ -35,6 +35,8 @@ def fetch_supported_languages():
if type(engines_languages[engine_name]) == list: if type(engines_languages[engine_name]) == list:
engines_languages[engine_name] = sorted(engines_languages[engine_name]) engines_languages[engine_name] = sorted(engines_languages[engine_name])
print("fetched languages from %s engines" % len(engines_languages))
# write json file # write json file
with open(engines_languages_file, 'w', encoding='utf-8') as f: with open(engines_languages_file, 'w', encoding='utf-8') as f:
json.dump(engines_languages, f, indent=2, sort_keys=True) json.dump(engines_languages, f, indent=2, sort_keys=True)
@ -97,7 +99,11 @@ def join_language_lists(engines_languages):
country_name = '' country_name = ''
if locale: if locale:
# get country name from babel's Locale object # 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()} 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 =",
) )
language_codes = tuple( language_codes = []
[
( for code in sorted(languages):
code,
languages[code]['name'].split(' (')[0], name = languages[code]['name']
languages[code].get('country_name') or '', if name is None:
languages[code].get('english_name') or '', print("ERROR: languages['%s'] --> %s" % (code, languages[code]))
) continue
for code in sorted(languages) 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: with open(languages_file, 'w') as new_file:
file_content = "{file_headers} \\\n{language_codes}".format( file_content = "{file_headers} \\\n{language_codes}".format(