How to use linebreaks and other HTML tags in XLIFF translation files with Neos Flow

With the Neos Flow PHP framework, you can use XLIFF to manage translations in your application.

If you have labels containing HTML tags like <br /> or <em> for (linebreak or emphasis), these will normally be escaped.

To have the HTML formatting “kick in”, use CDATA in your XLIFF file like this

<trans-unit id="user.created" xml:space="preserve">
   <target><![CDATA[This is first line.<br />
This is the next line.]]></target>
</trans-unit>

And remember to change the printing in your Fluid template to use a raw ViewHelper, so the HTML is not being escaped and printed.

It is done like this

<p>{f:translate(id: 'user.created') -> f:format.raw()}</p>

And the linebreak will be printed.

Before you use the raw ViewHelper for everything!

Your translations labels are controlled by you, so we can use the raw ViewHelper to print the content directly. But do not use it for user submitted content with cleaning it up first.

Now I’ve said it, and I hope you remember it