How to configure plurals in XTM Cloud

Introduction

As you might know, different languages have a different number of plural forms available for them. The simplest example is one month and many months in English, vs. one miesiąc, one and a half miesiąca, two-three-four miesiące, and many miesięcy in Polish. This is a challenge in localization if you want to localize your applications or web content and a sentence contains a number of items as a variable instead of as a specific number.


Specifics

Supported file formats

XTM Cloud can handle the localization of plurals in four file formats:

  • Android XML,

  • JSON with ICU syntax,

  • PO/POT,

  • Stringdict (IOS).

By default, handling plurals is disabled.

IMPORTANT!

Keep in mind that enabling plurals in your filter template comes with the change in file naming convention. The code of the project’s target language is appended to the end of the source file name. This is expected behavior and cannot be changed in any way.

IMPORTANT!

Keep in mind that enabling plurals in your filter template comes with the change in file naming convention. The code of the project’s target language is appended to the end of the source file name. This is expected behavior and cannot be changed in any way.

Determining the number of plurals for a particular language

Keep in mind that different languages have a different number of plural forms available for them. To find out more about the actual number of plurals for a particular language, visit the following website: https://cldr.unicode.org/index/downloads.

IMPORTANT!

The number of plural forms in a source file should be consistent with the number of plurals in the source language. In the target file, there will be as many plurals as set in its corresponding target language in the back-end of the XTM Cloud instance (configurable by the XTM International Support team).

Plurals syntax in particular file formats

JSON with ICU

IMPORTANT!

Note that the ICU syntax is only handled as plurals in JSON files!

The ICU content is inside curly brackets. It starts with the name of a variable, which can be used in the segment, but does not have to. Then it specifies whether this is a selection of plurals or selection of some other fixed variables. Then it lists keywords and has the sentences in curly brackets immediately after each keyword.

{ "your-sample-plural-segment": "{num, plural, one {Selected {num} item} other {Selected {num} items}}", "your-sample-select-segment": "{gender, select, female {She is here} male {He is here} other {They are here}}", "your-sample-normal-segment": "I am a sample normal segment." }

In XTM Cloud, the processing of plurals is disabled by default. To enable it, create a suitable ticket for the XTM International Support team and provide details (it is recommended that you have segment IDs and comments for this).

To adjust the plural count for a particular target language, create a suitable ticket for the XTM International Support team and provide details.

  • See attached an example of a correctly-structured JSON file:.

  • Also see the content in XTM Workbench:

Android XML

See the example Android XML file structure. The syntax is pretty self-explanatory.

<?xml version="1.0" encoding="utf-8"?> <resources> <string name="your-sample-normal-segment">I am a sample normal segment.</string> <plurals name="your-sample-plural-segment"> <item quantity="one">Selected %1$d item.</item> <item quantity="other">Selected %1$d items.</item> </plurals> <string-array name="your-sample-array-segment"> <item>first item in array</item> <item>second item in array</item> <item>third item in array</item> </string-array> </resources>

As in the case of JSON files, plurals processing is also turned off by default. To enable it, create a suitable ticket for the XTM International Support team and provide details (it is recommended that you have segment ID and comments enabled for this).

The method for adjusting the default plural count for a particular target language basically works in exactly the same way as for JSON ICU as we cannot differentiate the file for which it is being set.

  • See attached an example of a correctly-structured Android XML file:

  • Also, see the content in XTM Workbench:

PO/POT files

PO files are bilingual but, by default, only segments without translations are extracted for translation. Again, it can be adequately configured by the XTM International Support team. See an example structure:

msgid "" msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Language: enUS\n" "Plural-Forms: nplurals=2; plural=n != 1;" #: sample #, python-format msgid "Selected %(num_items)s item" msgid_plural "Selected %(num_items)s items" msgstr[0] "" msgstr[1] "" msgid "" "I am a sample normal segment" msgstr ""

IMPORTANT!

A PO file with plurals contains a Plural-Forms: (…) line in its metadata, and every segment with plurals must have an adequate line too. XTM Cloud uses this line to identify that the file contains plurals and exactly how many of them there are. On target generation, this line will be replaced with one that is appropriate for the target language.

Plural forms will be activated in PO files straight away if XTM Cloud finds a Plural-Forms: (…) line in the file, as described above. Additionally, the msgid_plural element must be present for each segment that is supposed to be processed as plurals.

To adjust the plural count for a particular target language, create a suitable ticket for the XTM International Support team and provide details.

  • See attached an example of a correctly-structured PO file:

  • Also see the content in XTM Workbench:

Stringsdict files

Stringsdict files are used for translating iOS applications, and their file looks quite different from Android files:

Stringsdict have plurals enabled by default and no additional configuration is required.

To adjust the plural count for a particular target language, create a suitable ticket for the XTM International Support team and provide details.

  • See attached an example of a correctly-structured Stringsdict file:

  • Also see the content in XTM Workbench: