Skip to content

Commit

Permalink
adapt sync_strings to crowdin outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
oxygen-dioxide committed Jan 1, 2025
1 parent 2ee8599 commit 5e8d701
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Misc/sync_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
import xml.etree.ElementTree as ET
import xml.dom.minidom as MD

import json

def register_all_namespaces(filename):
namespaces = dict(
Expand Down Expand Up @@ -58,15 +58,22 @@ def dict_to_file(filename, dict, en_dict):
lang_files = os.listdir(dir)
src_file = next(filter(lambda f: f.endswith("Strings.axaml"), lang_files))
src_file = os.path.join(dir, src_file)
dst_files = filter(lambda f: not f.endswith("Strings.axaml"), lang_files)
dst_files = filter(lambda f: f.endswith("axaml") and not f.endswith("Strings.axaml"), lang_files)
dst_files = map(lambda f: os.path.join(dir, f), dst_files)

register_all_namespaces(src_file)
en_dict = file_to_dict(src_file)
dict_to_file(src_file, en_dict, None)

#strings unhandled by crowdin
unhandled_strings = json.load(open(os.path.join(dir, "unhandled_strings.json"), "r", encoding='utf8'))

for dst_file in dst_files:
language = os.path.basename(dst_file).split('.')[1]
dst_dict = file_to_dict(dst_file)
for (key, item) in unhandled_strings.items():
if(language in item["translations"]):
dst_dict[key] = (item["tag"], item["translations"][language])
to_remove = set(dst_dict.keys()) - set(en_dict.keys())
to_add = set(en_dict.keys()) - set(dst_dict.keys())
[dst_dict.pop(k) for k in to_remove]
Expand Down
11 changes: 11 additions & 0 deletions OpenUtau/Strings/unhandled_strings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

{
"ui.fontfamily": {
"tag": "FontFamily",
"translations": {
"ja-JP": "Meiryo UI,Hiragino Sans,Segoe UI,San Francisco,Helvetica Neue",
"th-TH": "Noto serif Thai,Angsana New,Noto Sans Thai,IBM Plex Sans Thai,Segoe UI,San Francisco,Helvetica Neue",
"zh-CN": "Microsoft YaHei UI,PingFang SC,Segoe UI,San Francisco,Helvetica Neue"
}
}
}

0 comments on commit 5e8d701

Please sign in to comment.