Xcode 6, XLIFF, and straight quotes

It’s a nice thing that Xcode 6 added better localization tools. With any Xcode project, you can now select the project file in the outline on the left and from the Editor menu choose Export for Localization… which will produce XLIFF files for each of the enabled localization. You can then send the files to those who will make the translation.

The export function grabs strings to translate from your Interface Builder and Storyboard files, but also directly from your code if you are using NSLocalizedString to get those strings:

NSLocalizedString(@"Grab Handle to Change Location", @"Tooltip");

It’ll also work with Swift:

NSLocalizedString("Grab Handle to Change Location", comment: "Tooltip")

Once you have the XLIFF files for each localization, translators for each language can edit them with an editor (such as Counterparts Lite), or they can edit the XML content themselves if they are confortable with that. You can then later import any changes made to those translations

But right now there’s a glaring bug in Xcode 6.1 that’ll make strings with straight quotes export as garbage in XLIFF files. So if you have this in your code:

NSLocalizedString(@"He said \"Hello!\"", @"Straight quotes test");

you’ll get incorrect strings when exporting for localization. If you import XLIFF files with straight quotes in your project, expect those to be mangled once you reexport them.

I would suggest the use “curly” quotes instead of "straight" ones. Actually, you should always use curly quotes: they’re prettier an more typographically correct, and your app will look better.


Follow-ups


  • © 2003–2017 Michel Fortin.