mirror of
https://github.com/YunoHost/apps.git
synced 2024-09-03 20:06:07 +02:00
[enh] script to extract translation from a built manifest
This commit is contained in:
parent
99e6e3648d
commit
2541b4e377
1 changed files with 47 additions and 0 deletions
47
generate_translation_file.py
Normal file
47
generate_translation_file.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
import os
|
||||
import sys
|
||||
import json
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
builded_file = json.load(open(sys.argv[1], "r"))
|
||||
|
||||
other_langs = {}
|
||||
|
||||
keys = []
|
||||
|
||||
en = {}
|
||||
|
||||
for app, data in builded_file.items():
|
||||
key = "%s_manifest_description" % app
|
||||
en[key] = data["manifest"]["description"]["en"]
|
||||
keys.append(key)
|
||||
|
||||
for i in data["manifest"]["description"]:
|
||||
if i not in other_langs:
|
||||
other_langs[i] = {x: "" for x in keys}
|
||||
|
||||
for i, translations in other_langs.items():
|
||||
translations[key] = data["manifest"]["description"].get(i, "")
|
||||
|
||||
for i, questions in data["manifest"]["arguments"].items():
|
||||
for question in questions:
|
||||
key = "%s_manifest_arguments_%s_%s" % (app, i, question["name"])
|
||||
en[key] = question["ask"]["en"]
|
||||
|
||||
keys.append(key)
|
||||
|
||||
for i in question["ask"]:
|
||||
if i not in other_langs:
|
||||
other_langs[i] = {x: "" for x in keys}
|
||||
|
||||
for i, translations in other_langs.items():
|
||||
translations[key] = question["ask"].get(i, "")
|
||||
|
||||
if not os.path.exists("locales"):
|
||||
os.makedirs("locales")
|
||||
|
||||
open("locales/en.json", "w").write(json.dumps(en, sort_keys=True, indent=4))
|
||||
|
||||
for i, translations in other_langs.items():
|
||||
open("locales/%s.json" % i, "w").write(json.dumps(translations, sort_keys=True, indent=4))
|
Loading…
Add table
Reference in a new issue