Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Version History

« Previous Version 2 Next »

Introduction

As you may 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 wish to localize your applications or Web content where the sentence contains a number of things as a variable instead of as a specific number.


Specifics

Supported file formats

XTM can handle localization of plurals in four file formats:

  • Android XML;

  • JSON with ICU syntax;

  • PO/POT,

  • Stringdict (IOS).

By default handling plurals is turned off.

Determining the number of plurals for a given language

Keep in mind that different languages have a different number of plural forms available for them. In order to find out more on the actual number of plurals for a given language, please, visit the the following website: https://unicode-org.github.io/cldr-staging/charts/latest/supplemental/language_plural_rules.html.

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 it is set in its corresponding target language on the back-end side of the XTM instance (configurable by the XTM Support team).

Plurals syntax in respective file formats

JSON with ICU

IMPORTANT!

Please, note that the ICU syntax is handled as plurals only in the 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 directly 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."
}

The processing of plurals in XTM is turned off by default. To turn it on, please, raise a proper ticket with such request to the XTM Support team and provide details (it is recommended to have segment ID and comments set up for this).

For adjusting the plural count for a given target language, please, raise a proper ticket with such request to the XTM Support team and provide details.

Please, see attached an exemplary, correctly-structured JSON file:

Also, please, see the content in Workbench:

Android XML

Please, see the exemplary structure of the Android XML file. 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, the plurals processing is also turned off by default. To turn it on, please, raise a proper ticket with such request to the XTM Support team and provide details (it is recommended to have segment ID and comments set up for this).

As for adjusting the default plural count for a given target language, it basically works exactly the same as for JSON ICU, as we cannot differentiate for which file it is being set.

Please, see attached an exemplary, correctly-structured Android XML file:

Also, please, see the content in Workbench:

PO/POT files

PO files are bilingual, but by default, only segments without translation are extracted for translation. Again, it can be adequately configured by the XTM Support team. Please, see an exemplary 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 adeqaute line too. It is thanks to this line that XTM recognizes that the file contains plurals and their exact number. Upon target generation, this line will be replaced with one that is appropriate for the target language.

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

For adjusting the plural count for a given target language, please, raise a proper ticket with such request to the XTM Support team and provide details.

Please, see attached an exemplary, correctly-structured PO file:

Also, please, see the content in Workbench:

Stringsdict files

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

<plist version="1.0">
    <dict>
        <key>Selected_items</key>
        <dict>
            <key>NSStringLocalizedFormatKey</key>
            <string>%1$#@items@</string>
            <key>items</key>
            <dict>
                <key>NSStringFormatSpecTypeKey</key>
                <string>NSStringPluralRuleType</string>
                <key>NSStringFormatValueTypeKey</key>
                <string>d</string>
                <key>zero</key>
                <string>Selected %d items</string>
                <key>one</key>
                <string>Selected %d item</string>
                <key>other</key>
                <string>Selected %d items</string>
            </dict>
        </dict>
    </dict>
</plist>

Stringsdict have plurals switched on by default, and no additional configuration is required.

For adjusting the plural count for a given target language, please, raise a proper ticket with such request to the XTM Support team and provide details.

Please, see attached an exemplary, correctly-structured Stringsdict file:

Also, please, see the content in Workbench:

  • No labels