Untitled
python
a month ago
840 B
1
Indexable
Never
import xml.etree.ElementTree as ET original_xml_path = "original.xml" translated_xml_path = "translated.xml" merged_xml_path = "merged.xml" # Load original and translated XMLs original_tree = ET.parse(original_xml_path) original_root = original_tree.getroot() translated_tree = ET.parse(translated_xml_path) translated_root = translated_tree.getroot() # Map translations translations = {} for item in translated_root.findall("item"): key = item.find("key").text value = item.find("value").text translations[key] = value # Apply translations to the original XML for translation in original_root.findall('translation'): key = translation.get('id') if key in translations: translation.text = translations[key] # Save the merged XML original_tree.write(merged_xml_path, encoding='utf-8', xml_declaration=True)