Overview

Plurals

Smartling supports plural sensitive translation of strings. In order for strings to have pluralized translations, your development platform must also be able to support plural strings. Your application development platform will determine exactly how you can create plural strings in your Smartling project. Typically, this is achieved through special APIs/functions/methods that allow the developer to identify strings that need to be pluralized and provide a quantity variable.  The appropriate form of the string is selected at runtime according to the quantity variable and the language. Smartling currently supports plural strings in YAML, Gettext, QT TS Linguist, Android XML, iOS stringsdict, and JSON ICU files, as well as in Global Delivery Network (GDN) projects.

Smartling’s support for plurals is based on the Unicode CLDR standard. We support two CLDR forms for English; One and Other (which correspond to the ‘singular’ and ‘plural’ forms in English grammar). If a string is captured as a plural string, we will ask translators to provide the correct number and type of forms - based on CLDR - for each language. We will then deliver the translations in the correct number of forms in the translated file or via the localized GDN site.  For files this means keys may be added/inserted  or removed depending on the target language. The number of forms for a specific target language can be more or less than the forms for the source language.

For the majority of languages we support CLDR version 27. Newer versions of the CLDR standard have updated the rules of pluralization for some languages. Some languages have been updated to the more up-to-date rules published in the CLDR specification.

 

Best Practices for Working with Plurals

  • Carefully review your native support (platform or selected library) and avoid “rolling your own” solution for plurals.
  • Keep plural strings simple; use only a single quantity variable in a string.
  • Include the quantity variable in all of the original forms of the string to avoid confusing translators.

In your application code, deploying a plural string will look something like this:

Example:

String rooms = format(‘rooms_available', $rooms_available_count);
print($rooms);

In this example, $rooms_available_count is the quantity variable, used to look up the correct form of the rooms_available string. In a YAML file, your rooms_available might look something like this:

Example:

rooms_available:
     one: “%{rooms_available_count} room available.”
     other: “%{rooms_available_count} rooms available.”

Avoid constructions like these:

Example:

# Do NOT do this. This is example of something not supported.
rooms_available:
     zero: “Zilch.”
     # Zero is not a standard form for English in CLDR.
     one: “Last room available.”
     # Each standard form should refer to the quantity variable.
     other: “%{rooms_available_count} rooms available.”

Plural strings should conform to the CLDR standards for plural forms, should always refer to the quantity variable and should only differ as much as is necessary for correct grammar in the target language. If you want to handle a specific quantity in a special way, for example: “Sorry, there are no rooms available!” or “Hurry, there is only one room left!”, use conditional statements in your application logic to fetch a different, non-plural string.

Plurals for Gettext Files

Plural sensitive forms for Gettext files are indicated by the source .pot file having a string marked ‘msgid_plural’.

Example:

msgid “added %d item to cart”
msgid_plural “added %d items to cart”
msgstr[0] “”
msgstr[1] “”

Once translated, the downloaded .po file will have the plural forms needed for the target language and the appropriate language-specific headers. Smartling returns the PluralForm header in the top of the file (if it existed in the original file) that contains the correct plurals rules for that locale.

Gettext files have limited support for some locales. For more information on Gettext plural forms, see: Additional functions for plural forms

Plurals for YAML Files

Plural sensitive forms for YAML files are indicated at the sub-key level. For example, the one and other keys in the following English source file indicate that the string is plural sensitive:

Example:

image_upload_timestamp:
     one: "uploaded %{num_secs} second ago"
     other: "uploaded %{num_secs} seconds ago"

You can turn on detection of plurals using the following directive: # smartling.plurals_detection = on

Plurals for JSON Files

Plurals are supported for JSON files if the entire file is formatted as ICU MessageFormat. JSON files uploaded with the Smartling string directive for ICU MessageFormat can have plural strings when using the ICU MessageFormat plural string type. ICU MessageFormat encompasses a number of features for formatting strings in addition to plurals. Here are is an example of an ICU MessageFormat plural strings in a JSON file:

Examples:

"stringKey" : "{people_count, plural, one {{people_count} person here.} other {{people_count} people here.}}"

Plurals for QT TS Files

Plural sensitive forms for QT Linguist files are indicated by the source string having “numerus = “yes” and the variations using the “numerusform” element with the “plurality” attribute.

Example:

<message numerus="yes">
  <source>%1 subtitle(s) extracted</source>
  <translation>
     <numerusform plurality="singular">%1 subtitle extracted</numerusform>
     <numerusform plurality="plural">%1 subtitles extracted</numerusform>
  </translation>
</message>

Plurals for Android Files

Plural sensitive forms for Android files are indicated by the source file having a string in a 'plurals' element with the forms in 'item' elements. The CLDR form is indicated by the quantity attribute.

Example:

<plurals name="plural_strings2">
   <item quantity="one">You have %s item in your cart.</item>
   <item quantity="other">You have %s items in your cart.</item>
</plurals>

Smartling conforms to the Android standard for plurals: http://developer.android.com/guide/topics/resources/string-resource.html#Plurals.

Plurals for iOS Files

Apple has released the Stringsdict file format to handle plurals. Please refer to the Apple documentation for the file format, which uses the  standard CLDR  forms.

Prior to releasing the Stringdict file format, Smartling extended iOS strings format by developing an open source library to accommodate plurals. We now recommend you use Apple's built-in support.

 

Plurals in the GDN

Plural strings in the GDN are identified by wrapping the quantity variable in <span class="sl_plural"> tags.  Smartling will ingest a plural sensitive string when there is one variable using this class in the string.

Was this article helpful?