forked from REAPER-CN/ReaperLangPack-zh_CN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge.py
49 lines (43 loc) · 1.35 KB
/
merge.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
47
48
49
#encoding: utf-8
def read_tranlated(fn):
translated = {}
for line in open(fn):
line = line.rstrip('\r\n')
print line
if not line:
continue
if line.startswith('#'):
continue
if line.startswith(';'):
continue
if line.startswith('['):
continue
key, trans = line.split('=', 1)
translated[key] = trans
return translated
def merge(translated_file, new_template_file, merged_file):
translated = read_tranlated(translated_file)
fp = open(merged_file, 'w')
fp.write('#NAME:简体中文 (Kommit 汉化)\n')
cnt = 0
for line in open(new_template_file):
if not line.startswith(';'):
fp.write(line)
continue
if line.startswith(';^'):
fp.write(line)
continue
key = line[1:].split('=')[0]
if key in translated:
trans = translated[key]
fp.write('%s=%s\n' % (key, trans))
del translated[key]
cnt += 1
else:
fp.write(line)
print '%s merged' % cnt
for k, v in translated.items():
print k, v.decode('utf-8')
fp.close()
if __name__ == '__main__':
merge('zh_CN.ReaperLangPack.old', 'template_v501.ReaperLangPack', 'zh_CN.ReaperLangPack')