Untitled

mail@pastecode.io avatar
unknown
python
a year ago
723 B
3
Indexable
import sys
import xml.etree.ElementTree as ET

if len(sys.argv) != 3:
    print("Usage: xtb_to_xml.py <input.xtb> <output.xml>")
    sys.exit(1)

input_xtb = sys.argv[1]
output_xml = sys.argv[2]

# Parse the input XTB file
tree = ET.parse(input_xtb)
root = tree.getroot()

# Create a new XML tree for output
out_root = ET.Element("root")

for entry in root.findall('translation'):
    key = entry.get('id')
    value = entry.text if entry.text else ''
    
    item = ET.SubElement(out_root, "item")
    ET.SubElement(item, "key").text = key
    ET.SubElement(item, "value").text = value

# Write to the output XML file
out_tree = ET.ElementTree(out_root)
out_tree.write(output_xml, encoding='utf-8', xml_declaration=True)