blob: 37fdfdae8fc76c76d48736a6722d5075ec8e37c1 [file] [log] [blame]
Marco Brohetf9d4a5b2014-02-27 15:02:24 +01001#!/usr/bin/python2
2
3from xml.dom import minidom
Marco Brohetf9d4a5b2014-02-27 15:02:24 +01004
5def create_cm_caf_xml(strings_base, strings_cm, path):
6 # Load AOSP file and resources
7 xml_base = minidom.parse(strings_base)
8 list_base_string = xml_base.getElementsByTagName('string')
9 list_base_string_array = xml_base.getElementsByTagName('string-array')
10 list_base_plurals = xml_base.getElementsByTagName('plurals')
11
12 # Load CM file and resources
13 xml_cm = minidom.parse(strings_cm)
14 list_cm_string = xml_cm.getElementsByTagName('string')
15 list_cm_string_array = xml_cm.getElementsByTagName('string-array')
16 list_cm_plurals = xml_cm.getElementsByTagName('plurals')
17
18 # All names from CM
19 names_cm_string = []
20 names_cm_string_array = []
21 names_cm_plurals = []
22 # All names from AOSP
23 names_base_string = []
24 names_base_string_array = []
25 names_base_plurals = []
26
27 # Get all names from CM
28 for s in list_cm_string :
29 if not s.hasAttribute('translatable') and not s.hasAttribute('translate'):
30 names_cm_string.append(s.attributes['name'].value)
31 for s in list_cm_string_array :
32 if not s.hasAttribute('translatable') and not s.hasAttribute('translate'):
33 names_cm_string-array.append(s.attributes['name'].value)
34 for s in list_cm_plurals :
35 if not s.hasAttribute('translatable') and not s.hasAttribute('translate'):
36 names_cm_plurals.append(s.attributes['name'].value)
37
38 # Get all names from AOSP
39 for s in list_base_string :
40 if not s.hasAttribute('translatable') and not s.hasAttribute('translate'):
41 names_base_string.append(s.attributes['name'].value)
42 for s in list_base_string_array :
43 if not s.hasAttribute('translatable') and not s.hasAttribute('translate'):
44 names_base_string_array.append(s.attributes['name'].value)
45 for s in list_base_plurals :
46 if not s.hasAttribute('translatable') and not s.hasAttribute('translate'):
47 names_base_plurals.append(s.attributes['name'].value)
48
49 # Search for different names. If so, output the full line
50 t = 5
51
52 for z in names_cm_string:
53 if not z in names_base_string:
54 if t == 5:
55 f = open(path + '/cm_caf.xml','w')
56 f.write('<?xml version="1.0" encoding="utf-8"?>\n')
57 f.write('<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">\n')
58 t = 4
Marco Brohetf9d4a5b2014-02-27 15:02:24 +010059 f.write(list_cm_string[names_cm_string.index(z)].toxml() + '\n')
60 for z in names_cm_string_array:
61 if not z in names_base_string_array:
62 if t == 5:
63 f = open(path + '/cm_caf.xml','w')
64 f.write('<?xml version="1.0" encoding="utf-8"?>\n')
65 f.write('<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">\n')
66 t = 4
Marco Brohetf9d4a5b2014-02-27 15:02:24 +010067 f.write(list_cm_string_array[names_cm_string_array.index(z)].toxml() + '\n')
68 for z in names_cm_plurals:
69 if not z in names_base_plurals:
70 if t == 5:
71 f = open(path + '/cm_caf.xml','w')
72 f.write('<?xml version="1.0" encoding="utf-8"?>\n')
73 f.write('<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">\n')
74 t = 4
Marco Brohetf9d4a5b2014-02-27 15:02:24 +010075 f.write(list_cm_plurals[names_cm_plurals.index(z)].toxml() + '\n')
76
77 if t == 4:
78 f.write('</resources>')
79 f.close()