(path, nodeXPath, elementNames, attributes)
| 43 | invokeXGettext(current_file) |
| 44 | |
| 45 | def processXmlFile(path, nodeXPath, elementNames, attributes): |
| 46 | print("Processing XML file: " + path) |
| 47 | |
| 48 | doc = ElementTree.parse(path) |
| 49 | |
| 50 | elements = doc.findall(nodeXPath) |
| 51 | |
| 52 | found_values = [] |
| 53 | |
| 54 | for element in elements: |
| 55 | if len(attributes) > 0: |
| 56 | for attr in attributes: |
| 57 | if element.attrib.get(attr): |
| 58 | found_values.append(element.attrib.get(attr)) |
| 59 | else: |
| 60 | if len(elementNames) == 0: |
| 61 | # Get the actual value of the element |
| 62 | print(element.text) |
| 63 | found_values.append(element.text) |
| 64 | else: |
| 65 | for elementName in elementNames: |
| 66 | if element.tag == elementName and not element.text is None: |
| 67 | #print('Found ' + element.tag) |
| 68 | found_values.append(element.text) |
| 69 | |
| 70 | # Now generate a dummy C++ file for xgettext to parse |
| 71 | |
| 72 | if len(found_values) > 0: |
| 73 | |
| 74 | dummy_file = "xml_file_content.cpp" |
| 75 | |
| 76 | file = open(dummy_file, "w") |
| 77 | |
| 78 | for value in found_values: |
| 79 | value = value.replace("\n", "\\n") |
| 80 | value = value.replace("\"", "\\\"") |
| 81 | file.write('_("' + value + '")' + "\n") |
| 82 | |
| 83 | file.close() |
| 84 | |
| 85 | invokeXGettext(dummy_file) |
| 86 | |
| 87 | os.remove(dummy_file) |
| 88 | |
| 89 | print("------- Scanning C++ Files ----------------"); |
| 90 |
no test coverage detected