blob: b81534db220924df67af228b278a1cae8b928489 [file] [log] [blame]
Marco Brohetf9d4a5b2014-02-27 15:02:24 +01001#!/usr/bin/python2
2
3from xml.dom import minidom
4from subprocess import check_output
5
6#print('Welcome to the CyanogenMod Crowdin synchronization script')
7#print('---------------------------------------------------------\n')
8
9# Execute normal Crowdin sync
10#print('---------------------------------------------------------')
11#print('Executing normal Crowdin synchronization.................')
12#print(check_output(["java", "-jar", "crowdin-cli.jar", "upload", "sources"]))
13#print('Normal Crowdin synchronization complete..................')
14#print('---------------------------------------------------------\n')
15
16# Execute CAF search
17#print('---------------------------------------------------------')
18#print('Executing CAF search.....................................')
19
20def create_cm_caf_xml(strings_base, strings_cm, path):
21 # Load AOSP file and resources
22 xml_base = minidom.parse(strings_base)
23 list_base_string = xml_base.getElementsByTagName('string')
24 list_base_string_array = xml_base.getElementsByTagName('string-array')
25 list_base_plurals = xml_base.getElementsByTagName('plurals')
26
27 # Load CM file and resources
28 xml_cm = minidom.parse(strings_cm)
29 list_cm_string = xml_cm.getElementsByTagName('string')
30 list_cm_string_array = xml_cm.getElementsByTagName('string-array')
31 list_cm_plurals = xml_cm.getElementsByTagName('plurals')
32
33 # All names from CM
34 names_cm_string = []
35 names_cm_string_array = []
36 names_cm_plurals = []
37 # All names from AOSP
38 names_base_string = []
39 names_base_string_array = []
40 names_base_plurals = []
41
42 # Get all names from CM
43 for s in list_cm_string :
44 if not s.hasAttribute('translatable') and not s.hasAttribute('translate'):
45 names_cm_string.append(s.attributes['name'].value)
46 for s in list_cm_string_array :
47 if not s.hasAttribute('translatable') and not s.hasAttribute('translate'):
48 names_cm_string-array.append(s.attributes['name'].value)
49 for s in list_cm_plurals :
50 if not s.hasAttribute('translatable') and not s.hasAttribute('translate'):
51 names_cm_plurals.append(s.attributes['name'].value)
52
53 # Get all names from AOSP
54 for s in list_base_string :
55 if not s.hasAttribute('translatable') and not s.hasAttribute('translate'):
56 names_base_string.append(s.attributes['name'].value)
57 for s in list_base_string_array :
58 if not s.hasAttribute('translatable') and not s.hasAttribute('translate'):
59 names_base_string_array.append(s.attributes['name'].value)
60 for s in list_base_plurals :
61 if not s.hasAttribute('translatable') and not s.hasAttribute('translate'):
62 names_base_plurals.append(s.attributes['name'].value)
63
64 # Search for different names. If so, output the full line
65 t = 5
66
67 for z in names_cm_string:
68 if not z in names_base_string:
69 if t == 5:
70 f = open(path + '/cm_caf.xml','w')
71 f.write('<?xml version="1.0" encoding="utf-8"?>\n')
72 f.write('<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">\n')
73 t = 4
74 print('found string: ' + z)
75 f.write(list_cm_string[names_cm_string.index(z)].toxml() + '\n')
76 for z in names_cm_string_array:
77 if not z in names_base_string_array:
78 if t == 5:
79 f = open(path + '/cm_caf.xml','w')
80 f.write('<?xml version="1.0" encoding="utf-8"?>\n')
81 f.write('<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">\n')
82 t = 4
83 print('found string array: ' + z)
84 f.write(list_cm_string_array[names_cm_string_array.index(z)].toxml() + '\n')
85 for z in names_cm_plurals:
86 if not z in names_base_plurals:
87 if t == 5:
88 f = open(path + '/cm_caf.xml','w')
89 f.write('<?xml version="1.0" encoding="utf-8"?>\n')
90 f.write('<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">\n')
91 t = 4
92 print('found plurals: ' + z)
93 f.write(list_cm_plurals[names_cm_plurals.index(z)].toxml() + '\n')
94
95 if t == 4:
96 f.write('</resources>')
97 f.close()
98
99#print('Executing CAF search.....................................')
100#print('CAF search complete......................................')
101#print('---------------------------------------------------------\n')
102
103# Cleanup
104#print('---------------------------------------------------------')
105#print('Executing cleanup........................................')
106#print('Cleanup complete.........................................')
107#print('---------------------------------------------------------\n')
108
109# Committing
110#print('---------------------------------------------------------')
111#print('Executing commit.........................................')
112#print('Commit complete..........................................')
113#print('---------------------------------------------------------\n')
114
115# Done
116#print('Script is done. Goodbye!')