Lost in Symfony XLIFF translations
Tristan Roussel2 min read
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.