Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Plural variants are used whenever a numeric value is being dynamically passed into a translation string to ensure the accuracy and readability of sentences when there are zero, one or multiple things being referenced.

Singular and plural indicators

For plurals, we create different versions of a key followed by an underscore and the plural or singular indicator it represents.

Code Block
languagejs
{
  "key_zero": "zero",
  "key_one": "singular",
  "key_two": "two",
  "key_few": "few",
  "key_many": "many",
  "key_other": "other"
}

Most commonly, we will use the following indicator suffixes:

  • _zero for the string rendered when there are 0 of count

  • _one for the string rendered when there is 1 of count

  • _other for the string rendered when there is more than 1 of count

Using count indicators

In our JSON translation file:

Code Block
languagejs
        "status_testing_zero": "We are not missing test records or accounts for any library.",
        "status_testing_one": "We are missing test records or accounts for {{count}} library.",
        "status_testing_other": "We are missing test records or accounts for {{count}} libraries."

In our code, we use the string without the underscore and number, and the string will automatically adapt to count.

Code Block
languagejs
t('status_testing', {count: 0}); // -> "We are not missing test records or accounts for any library."
t('status_testing', {count: 1}); // -> "We are missing test records or accounts for 1 library."
t('status_testing', {count: 34}); // -> "We are missing test records or accounts for 34 libraries."

Reference