mirror of
https://github.com/YunoHost/apps.git
synced 2024-09-03 20:06:07 +02:00
[enh] add a script to separate translation between lists
This commit is contained in:
parent
ec4186505d
commit
4448496ef4
1 changed files with 40 additions and 0 deletions
40
separate_locales_between_lists.py
Normal file
40
separate_locales_between_lists.py
Normal 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))
|
Loading…
Add table
Reference in a new issue