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