I need help to correctly modify a xliff unit. My workflow is the following:
My input file is a docx and the first step is to extract a xliff file from it. I use tikal for this purpose and I get an xliff file where I have many transunit like the following one (as you see tikal fills automatically the target with the same source text):
xml <trans-unit id="tu3" xml:space="preserve"> <source xml:lang="it"><g id="1">Equazione di </g><x id="2"/><g id="3">Poisson</g><x id="4"/></source> <target xml:lang="en"><g id="1">Equazione di </g><x id="2"/><g id="3">Poisson</g><x id="4"/></target> </trans-unit>
Then I use the following code to extract all the strings that I want to translate:
from translate.storage import lisa, xliff f=open(filename,"r") inputfile = str(f.read()) XliffFile = xliff.xlifffile.parsestring(inputfile) for transunit in XliffFile.units: print transunit.source
which extract the correct sentence to translate from the transunit source
Equazione di Poisson
I send the sentence to a machine translation server and I get back the translated sentence (Poisson Equation)
And now I'm in trouble... I didn't find a simple solution to change the target in transunit with the translated sentence. I tried
In [50]: a.rich_target Out[50]: [<StringElem([<G(id="1" [u'Equazione di '])>, <X(id="2" [])>, <G(id="3" [u'Poisson'])>, <X(id="4" [])>])>] In [51]: a.target = "Poisson Equation"
but I get:
In [52]: a.target Out[52]: u'Poisson EquationEquazione di Poisson' In [53]: a.rich_target Out[53]: [<StringElem([<StringElem([u'Poisson Equation'])>, <G(id="1" [u'Equazione di '])>, <X(id="2" [])>, <G(id="3" [u'Poisson'])>, <X(id="4" [])>])>]
and this is not what I want... any suggestion in how to get the correct target? Thanks