Lost in Symfony XLIFF translations

XLIFF?

XLIFF is one of the 3 different formats you can use for translation in Symfony.
It is the recommended format because of its standard use by professional translators.

<trans-unit id="42">
    <source>french_food</source>
    <target>Omelette du fromage</target>
</trans-unit>

In Symfony, ids in XLIFF have no particular meaning, all you need is for them to be distinct in the same file.
Everything is about the source, which becomes the key in your translation catalogue once the file is loaded.
Usually, people use numbers as id, as you can see in Symfony documentation.

Problem with numbers

You have harder conflicts to resolve when working with git:
if two contributors used the same ids, one of them has to renumber its translations to be sure ids are unique.

If a contributor decides to rearrange the translations in a file to group them by category:

  • Either he/she renumbered all the ids and then it’s a nightmare with git.
  • Or the file is not sorted by id anymore, and you don’t know what the next id you have to use for the next translation is.

Simple solution

Do yourself a favor, use the source as the id!
No more meaningless number, no more headache with numbering.

<trans-unit id="french_food">
    <source>french_food</source>
    <target>Omelette du fromage</target>
</trans-unit>

One of the hidden benefits is that Symfony will now yell at you if you have a duplicated source in your file, whereas it was silently overwriting the duplications before.
Neat!

Edit: I updated Symfony documentation following this post since core contributors felt the same way as I do.


You liked this article? You'd probably be a good match for our ever-growing tech team at Theodo.

Join Us

  • Thanks for publishing this article. I agree completely with it. This is the strategy we use in a Symfony bundle that I manage and it’s working great for us. It’s a little bit more verbose, but the benefits are worth it.

  • Tristan Roussel

    Thanks for the comment! I proposed a change in Symfony docs to this end: https://github.com/symfony/symfony-docs/issues/6341