Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@alexislefebvre
Created December 11, 2018 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexislefebvre/eb1449838afac260fecde0e3b21a913b to your computer and use it in GitHub Desktop.
Save alexislefebvre/eb1449838afac260fecde0e3b21a913b to your computer and use it in GitHub Desktop.
Extract translations from Symfony XLF file to tab-separated plain text
# -*- 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