Created
December 11, 2018 16:30
-
-
Save alexislefebvre/eb1449838afac260fecde0e3b21a913b to your computer and use it in GitHub Desktop.
Extract translations from Symfony XLF file to tab-separated plain text
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
# -*- coding: utf-8 -*- | |
import xml.etree.ElementTree as ElementTree | |
filePath = 'translations/messages.fr.xlf' | |
f = open(filePath, 'r') | |
prefix = '{urn:oasis:names:tc:xliff:document:2.0}' | |
root = ElementTree.fromstring(f.read()) | |
for xmlFile in root.findall(prefix + "file"): | |
for unit in xmlFile.findall(prefix + 'unit'): | |
for segment in unit.findall(prefix + 'segment'): | |
source = segment.find(prefix + 'source').text | |
if (not source or source.find("mail") == -1): | |
continue | |
target = segment.find(prefix + 'target').text | |
if (source and target): | |
print(source + "\t" + target.replace("\n", '@')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment