When I click on Editor > Export for localization
to get my .xliff
file, there are some formatting errors that I cannot figure out how to fix.
Xcode is converting \n
into a literal new line.
Here is an example of the .xliff
file generated by Xcode, notice the difference between the <trans-unit>
tag and <source>
tag.
Does anyone know how to fix this issue to get the correct output? I need the <source>
tags to be one string with the \n
characters included. I can manually fix each problem, but I have over 1000 strings experiencing this problem and I cannot fix 1000 strings for each language.
Add a comment if you need more details on this issue.
If your XLIFF file looks like many XLIFF files I have seen where almost all lines end with a tag you could search for the regex ([^>])\n
and replace it by \1\\n
. Or ([^>])\r\n
, if your files contain Windows line breaks for some reason.
This is a workaround that may do the job for you. The best solution would be to get rid of hard-coded line breaks. As a translator I could not guess where the line breaks should go in the target language: is it after a fixed number of characters, or will it depend on the layout width of the target language text, i.e. depend on the font that is used? Translations from English into other languages are typically a fair bit longer than the original strings, so maybe the translator may have to insert more line breaks than the English string contains. If you have limited space in a layout column you should really create a method that determines where to wrap lines and not put this burden onto the translator: it will come back to you when you have to fix the layout for every target language.