mirror of https://github.com/kiwix/libkiwix.git
Handling of translation jsons w/o the language name
If a translation JSON file doesn't contain the 'name' (self-name) attribute of the translation language then that language is not included in the list of languages available in the UI language selector.
This commit is contained in:
parent
df4b16e485
commit
28673c1bb8
|
@ -29,7 +29,8 @@ def get_translation_info(filepath):
|
||||||
lang_code = Path(filepath).stem
|
lang_code = Path(filepath).stem
|
||||||
with open(filepath, 'r', encoding="utf-8") as f:
|
with open(filepath, 'r', encoding="utf-8") as f:
|
||||||
content = json.load(f)
|
content = json.load(f)
|
||||||
return lang_code, content["name"]
|
lang_name = content.get("name")
|
||||||
|
return lang_code, lang_name
|
||||||
|
|
||||||
language_list = []
|
language_list = []
|
||||||
json_files = translation_dir.glob("*.json")
|
json_files = translation_dir.glob("*.json")
|
||||||
|
@ -39,7 +40,11 @@ with open(resource_file, 'w', encoding="utf-8") as f:
|
||||||
continue
|
continue
|
||||||
print("Processing", i18n_file.name)
|
print("Processing", i18n_file.name)
|
||||||
if i18n_file.name != "test.json":
|
if i18n_file.name != "test.json":
|
||||||
language_list.append(get_translation_info(i18n_file))
|
lang_code, lang_name = get_translation_info(i18n_file)
|
||||||
|
if lang_name:
|
||||||
|
language_list.append((lang_code, lang_name))
|
||||||
|
else:
|
||||||
|
print(f"Warning: missing 'name' in {i18n_file.name}")
|
||||||
f.write(str(i18n_file.relative_to(script_path.parent)) + '\n')
|
f.write(str(i18n_file.relative_to(script_path.parent)) + '\n')
|
||||||
|
|
||||||
language_list = [{name: code} for code, name in sorted(language_list)]
|
language_list = [{name: code} for code, name in sorted(language_list)]
|
||||||
|
|
Loading…
Reference in New Issue