From 16ba58aad327ac178fd65f6bfecaf6ae7eb753d3 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Wed, 23 Mar 2022 23:54:04 +0800 Subject: [PATCH] lang.py for auto translate complete --- lang.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lang.py diff --git a/lang.py b/lang.py new file mode 100644 index 000000000..5afc87f9a --- /dev/null +++ b/lang.py @@ -0,0 +1,29 @@ +import os +import glob + +def get_lang(lang): + out = {} + for ln in open('./src/lang/%s.rs'%lang): + ln = ln.strip() + if ln.startswith('("'): + toks = ln.split('", "') + assert(len(toks) == 2) + a = toks[0][2:] + b = toks[1][:-3] + out[a] = b + return out + +def main(): + cn = get_lang('cn') + for fn in glob.glob('./src/lang/*'): + lang = os.path.basename(fn)[:-3] + if lang == 'cn': continue + not_transated = (set(cn.keys()) - set(get_lang(lang).keys())) + extra = '\n'.join(map(lambda x: ' ("%s", ""),'%x, not_transated)) + endstr = '].iter().cloned().collect();' + text = open(fn).read().replace(endstr, extra + '\n' + endstr) + with open(fn, 'wt') as fh: + fh.write(text) + + +main()