Xcode 6 localization of plurals & genders with XLIFF
Asked Answered
M

2

10

In Xcode 6 the XLIFF file format is now used for localization of strings. However, I need localise plurals and genders. How can I do this in Xcode 6?

As far as I understand, the XLIFF file now replaces the Localizable.strings file. In iOS 7/ OS X 10.9 we could localise plurals & genders by adding Localizable.stringsdict but this requires a Localizable.strings to exist. But since now there is no Localisable.strings file, how can I get the Localizable.stringsdict file to work?

Mocambique answered 3/10, 2014 at 12:50 Comment(0)
J
11

As of Xcode 6, Apple uses XLIFF as the file format for exporting your project for localization. However, nothing has changed inside the project itself. You should continue using Localisable.strings and Localizable.stringsdict files to handle plurals per Apple's documentation on Handling Noun Plurals and Units of Measurement.

You can refer to this Objective-C project or this Swift project as examples of using strings dictionary files for plurals with Xcode 6.

A little more background on XLIFF and Xcode 6:

XLIFF (XML Localisation Interchange File Format) is an XML-based format created to standardize the way localizable data are passed between tools during a localization process. XLIFF was standardized by OASIS in 2002.

When you click on Editor -> Export for Localization in Xcode, it packages up all of your localizable assets into an XLIFF file that can be handled off to translators for localizing your application's strings. Since XLIFF is a standardized file format, this means translators and translation tools do not need to understand Apple's internal strings format.

Here's an example of the resulting XLIFF document produced by exporting the above referenced Swift project for localization. Now translators can use a translation platform or tool to translate your application's content and return to you a localized XLIFF file. You, as a developer, can then use Xcode's "Import Localizations" feature to import the translated XLIFF file into your project. This will cause Xcode to generate the necessary locale specific strings files from the imported XLIFF.

In short, nothing has changed in how you develop your project. What's been added in Xcode 6 is a new feature to simplify the localization process.

There's one caveat that I should mention though about plurals and exporting for localization. As of Xcode 6.1, Apple's export for localization feature still lacks a way to properly export plurals. This is most likely due to the current XLIFF spec having no standardized way of managing plural representations of a string. There's an open bug with Apple to address this issue.

Jeroldjeroma answered 14/11, 2014 at 16:8 Comment(3)
So in short: if I have plurals, continue using Localizable.strings & Localizable.stringsdict. If I don't, then I can (but don't have to) use XLIFF. Can I not mix & match both, i.e. XLIFF for non-plural localization while using Localizable.strings/.stringsdict for plural localization? Or does it have to be one or the other?Mocambique
@iMaddin, you continue to use Localizable.strings/.stringsdict for plural localization. XLIFF is only an interchange format for exporting your strings from your project and importing translations back into your project. You do not have to use this new Xcode feature or XLIFF at all. It's there to simplify the process of working with translators who are used to XLIFF or translation platforms that support it. XLIFF is not a replacement for Apple's Localizable.strings/.stringsdict files.Jeroldjeroma
@Scott, the strings in .stringsdict file are not available in the en.xliff file, and you've mentioned that above as well. My question is: How do you manage that? Send .stringsdict file separately to translator?Combustible
R
3

XLIFF export has full support for plurals starting from Xcode 9

Xcode 9.0 Release Notes:

Added support to XLIFF for exporting and importing stringsdict files, including support for using the correct per-language plural variants. (16785521)

Refractory answered 12/12, 2018 at 8:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.