forked from rustdesk/rustdesk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlang.py
46 lines (39 loc) · 1.11 KB
/
lang.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
# Based on 'cn.rs', generate entries that are not completed in other languages
import os
import glob
def get_lang(lang):
out = {}
for ln in open('./src/lang/%s.rs'%lang):
ln = ln.strip()
if ln.startswith('("'):
k,v = line_split(ln)
out[k] = v
return out
def line_split(line):
toks = line.split('", "')
assert(len(toks) == 2)
k = toks[0][2:]
v = toks[1][:-3]
return k,v
def main():
for fn in glob.glob('./src/lang/*'):
lang = os.path.basename(fn)[:-3]
if lang in ['en','cn']: continue
fw = open("%s.rs.gen"%lang, "wb+")
dict = get_lang(lang)
for line in open('./src/lang/cn.rs'):
line_strip = line.strip()
if line_strip.startswith('("'):
k,v = line_split(line_strip)
if k in dict:
line = line.replace(v, dict[k])
else:
line = line.replace(v, "")
fw.write(line.encode())
else:
fw.write(line.encode())
fw.close()
os.remove("./src/lang/%s.rs"%lang)
os.rename(fw.name, "./src/lang/%s.rs"%lang)
main()