Skip to content

Instantly share code, notes, and snippets.

@mipapo
Created March 14, 2019 16:09
Show Gist options
  • Save mipapo/18575fc846815ebaa54e851670ab0727 to your computer and use it in GitHub Desktop.
Save mipapo/18575fc846815ebaa54e851670ab0727 to your computer and use it in GitHub Desktop.
xliff-remove trans-unit where source=target
#!/usr/bin/python2
from lxml import etree
from StringIO import StringIO
import sys
file = str(sys.argv[1])
NS = {'x':'urn:oasis:names:tc:xliff:document:1.2'}
tree = etree.parse(file)
locale_root = tree.getroot()
for trans_node in locale_root.xpath('//x:trans-unit', namespaces=NS):
source = trans_node.xpath('./x:source/text()', namespaces=NS)
target = trans_node.xpath('./x:target/text()', namespaces=NS)
if target == source:
trans_node.getparent().remove(trans_node)
f = open(file, "w")
f.write(etree.tostring(tree, pretty_print=True, xml_declaration=True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment