-
Notifications
You must be signed in to change notification settings - Fork 5
/
merge.py
43 lines (38 loc) · 1.7 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import xml.etree.ElementTree as ET
destTree = ET.parse('qt_zh_CN.ts')
destRoot = destTree.getroot()
srcTree = ET.parse('qtbase_ja.ts')
srcRoot = srcTree.getroot()
for srcContext in srcRoot.findall('context'):
hasThisContext = False
srcName = srcContext.find('name').text
for destContext in destRoot.findall('context'):
destName = destContext.find('name').text
if srcName == destName:
hasThisContext = True
for srcMessage in srcContext.findall('message'):
hasThisMessage = False
srcSource = srcMessage.find('source').text
for destMessage in destContext.findall('message'):
destSource = destMessage.find('source').text
if srcSource == destSource:
hasThisMessage = True
pass
if not hasThisMessage:
if not srcRoot.attrib['language'].startswith('zh'):
srcTranslation = srcMessage.find('translation')
srcTranslation.text = ''
srcTranslation.set('type', 'unfinished')
destContext.append(srcMessage)
if not hasThisContext:
if not srcRoot.attrib['language'].startswith('zh'):
for srcTranslation in srcContext.iter('translation'):
srcTranslation.text = ''
srcTranslation.set('type', 'unfinished')
destRoot.append(srcContext)
for destMessage in destRoot.iter('message'):
for destLocation in destMessage.findall('location'):
destMessage.remove(destLocation)
destTree.write('qt_zh_CN.ts', encoding='utf-8')