Dealing with pluralization in your translation project in Phrase

Different languages have different pluralization rules. This guide will show you how to handle plurals while translating in Phrase.

In the English language, there is only one singular and one plural form for a string, e.g. “one hotel” and “two hotels”. Other languages, such as Russian, Arabic, and many more, have quite different grammar rules, including additional plural forms.

Because of this, translators should always pay attention to the pluralization rules of the locale they are supposed to translate into and only fill out the forms they actually need.

How Phrase handles pluralization

Phrase knows about the pluralization rules of each language defined by the CLDR plural rules. Whenever you add a locale to your project and enter its ISO code, Phrase can support you with the pluralization process by only displaying the correct input fields for that language.

The following image shows the differences in the UI between English and Russian pluralization options:

Working with pluralization in Phrase

How to disable/enable pluralization

Pluralization can be enabled on a per-key basis. To mark a key as having pluralized translations, just edit the key settings and mark it as pluralized. Make sure to enter a pluralized name as well if required by the format you’re using (e.g. when using gettext).

The following image shows the setting option in the UI for pluralization:

Enabling pluralization in Phrase

Plurals per supported format

Phrase supports multiple localization file formats (see the list of supported formats here) and it will handle plural values accordingly. We provide a list of the most common ways you can support plural values for each format.

Using pluralization with YAML/Ruby i18n

The Ruby i18n gem uses named categories to identify the different pluralizations of a message. These categories are stored as subkeys of the message key itself and are named accordingly:

  • zero
  • one
  • two
  • few
  • many
  • other

For a key named inbox.messages.notification the following pluralizations will be available:

Key

Translation

inbox.messages.notification.zero          

You have no new messages
inbox.messages.notification.one You have one new message
inbox.messages.notification.other You have %[count] new messages

 

When uploading a YAML file, Phrase will identify pluralized keys and mark them accordingly. It will also store the already given pluralized translations as well. During the download process, Phrase will reconstruct the YAML document and put all pluralizations under their appropriate key.

Handling plurals for gettext files

The gettext format has a tight connection to the pluralization rules of the locale it contains. The concept basically contains of two aspects:

Header definition: nplurals

By selecting the correct language name for your locale within Phrase, the correct nplurals-definition can be fetched and will automatically be added to the file when you download it.

For example this is the Plurals definition for English:

Plural-Forms: nplurals=2; plural=n != 1;

Then for each message string you want to pluralized you need to add the following line before the translation string:

msgid_plural ""

Plural forms

Phrase automatically limits the pluralization categories in the exported files to the forms that are required for the selected locale. This ensures you will always receive valid gettext files that provide proper pluralized translations. Phrase will map the correct forms automatically for you.

Plurals for Symfony YAML files

Pluralization rules for the  Symfony i18n framework follow the ICU message format

Before you can use ICU message formats in the project, you need to enable it for the project. The option to enable is is located in the Project Settings > Advanced Tab.

Enable ICU message format support in Phrase

As the ICU MessageFormat natively supports pluralization there is no need to enable pluralization when you add new Keys.

Once, enabled you can use the select function syntax to pass multiple parameters adding the plural rule:

file:translations/messages+intl-icu.en.yaml

key: >-

  {files, plural,

     =0 {No messages received}

     one {One message received}

     =other {# messages received}

  }

You can add multiple rules for different numbers for example:

=0
=1
=2
=n

As always, Phrase will reconstruct the YAML document and put all pluralizations under their appropriate key.

Plurals for CSV files

The CSV files should be structured like this:

1 (Key column), 2 (Translation column), 3 (Comment column)
messages.zero,  No messages received,
messages.one,   One message received,
messages.other,  %s messages received,

Plurals for iOS Localizable Strings

IOS has a simple key value format for messages. For plural values just add the following postfix operators:

"messages.zero" = "No messages received";
"messages.one" = "One message received";
"messages.other" = "%s messages received";

Plurals for Android XML files

Android uses XML files for storing translation files. They are more verbose than usual. For plural values you need to assign a special <plurals> tag like this:

<plurals name="messages">
        <item quantity="one">One message received.</item>
        <item quantity="other">%s messages received.</item>
        <item quantity="zero">No messages received.</item>
</plurals>

Plurals for JSON files

JSON files are the most common format as it's easy to read and to parse. Bellow is the most common format of plural key messages on various libraries:

"messages": {
    "one": "One message received.",
    "other": "%s messages received.",
    "zero": "No messages received."
}

Learn even more about pluralization: