Created
March 14, 2019 16:09
-
-
Save mipapo/18575fc846815ebaa54e851670ab0727 to your computer and use it in GitHub Desktop.
xliff-remove trans-unit where source=target
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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