Moving locale/translation tools to a specific folder ... Need some work to revive this whole thing

This commit is contained in:
Alexandre Aubin
2020-03-31 01:31:04 +02:00
parent 63d5700e52
commit e2ab31336a
3 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,57 @@
import os
import sys
import json
if __name__ == '__main__':
if os.path.exists("locales/en.json"):
print "This script should be run only once, the first time to generate locales/, after that you should use update_translations.py"
print "Abort"
sys.exit(1)
other_langs = {}
keys = []
en = {}
for builded_file in sys.argv[1:]:
builded_file = json.load(open(builded_file, "r"))
for app, data in builded_file.items():
if "en" in data["manifest"]["description"]:
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 category, questions in data["manifest"]["arguments"].items():
for question in questions:
if "en" not in question["ask"]:
continue
key = "%s_manifest_arguments_%s_%s" % (app, category, 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))

View File

@ -0,0 +1,40 @@
import os
import sys
import json
# TODO
# when an app is moved from one list to another find a way to migrate string?
if __name__ == '__main__':
# en = json.load(open("locales/en.json", "r"))
for apps_list in sys.argv[1:]:
if not os.path.exists(apps_list):
print "Error: file %s doesn't exists" % apps_list
sys.exit(1)
folder = "locales-%s" % (apps_list.split(".")[0])
apps_list = json.load(open(apps_list, "r"))
apps = tuple(apps_list.keys())
if not os.path.exists(folder):
os.mkdir(folder)
for existing_translations in os.listdir("locales"):
if not existing_translations.endswith(".json"):
print "skip non json file %s", existing_translations
continue
language = existing_translations[:-len(".json")]
existing_translations = json.load(open("locales/" + existing_translations, "r"))
new_content = {}
for key, value in existing_translations.items():
if key.startswith(apps):
new_content[key] = value
file_name = folder + "/" + language + ".json"
print "writting %s..." % file_name
open(file_name, "w").write(json.dumps(new_content, sort_keys=True, indent=4))

View File

@ -0,0 +1,27 @@
import sys
import json
if __name__ == '__main__':
for builded_file in sys.argv[1:]:
app_list = builded_file.split("-")[0]
en = json.load(open("locales-%s/en.json" % app_list, "r"))
builded_file = json.load(open(builded_file, "r"))
for app, data in builded_file.items():
if "en" in data["manifest"]["description"]:
key = "%s_manifest_description" % app
en[key] = data["manifest"]["description"]["en"]
for category, questions in data["manifest"]["arguments"].items():
for question in questions:
if "en" in question["ask"]:
key = "%s_manifest_arguments_%s_%s" % (app, category, question["name"])
en[key] = question["ask"]["en"]
if "en" in question.get("help", {}):
key = "%s_manifest_arguments_%s_help_%s" % (app, category, question["name"])
en[key] = question["help"]["en"]
open("locales-%s/en.json" % app_list, "w").write(json.dumps(en, sort_keys=True, indent=4))