2
votes

I haven't understood exactly how the xliff and twig files work together with Symfony2.

In my twig I wrote this

<article>{{ 'bye'|trans }}</article>

and the it xliff file "Resurces/translations/messages.it.xliff" (this is just a snippet)

<trans-unit id="2" datatype="plaintext">
    <source xml:lang="en">Bye</source>
    <target xml:lang="it">Ciao</target>
</trans-unit>

It works good and when the url language-segment is "it", it translates in it language (Ciao).

Instead, How I can make a similar thing without fall in error?

<trans-unit id="2" datatype="plaintext">
    <source xml:lang="en"><a href="link.html">Bye</a></source>
    <target xml:lang="it"><a href="link.html">Ciao</a></target>
</trans-unit>

Above there's just an example of what I would like to do. I sow a lot of stuff about this matter but I'm still confused.

The problem is when I should translate a string with HTML tags inside.

1
Is this a question about how to offer different HTML based on the language? What do you want to translate? Should there be something like bye.html and ciao.html? - althaus
I would like to translate the entire string "<a href="link.html">Bye</a>" in "<a href="link.html">Ciao</a>". This have sense in such case like this: "<a href="link.html">Hi</a>, how are <b>you</b>?" - Roberto Rizzi
maybe it's better an example with a translate like below: "click <a href="link">here</a> for preview" in "clicca <a href="">qui</a> per l'anteprima" - Roberto Rizzi

1 Answers

1
votes

I've finally found the solution.

In my twig file:

{{ 'click <a href="#link">here</a> for more info'|trans|raw }}

in my xliff file ( trans-unit tag snippet):

<trans-unit id="3" datatype="html">
 <source xml:lang="en"><![CDATA[click <a href="#link">here</a> for more info]]></source>
 <target xml:lang="fr"><![CDATA[clicca <a href="#link">qui</a> per maggiori info]]></target> 
</trans-unit>

with en set up as main language.