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 version it represents.In our JSON indicator it represents.
Code Block | ||
---|---|---|
| ||
{
"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 | ||
---|---|---|
| ||
"status_knowntesting_zero": "We don'tare knownot aboutmissing anytest Hostrecords LMSor instancesaccounts thatfor are needed for {{consortium_name}}any library.", "status_knowntesting_one": "We knoware about {{count}} Host LMS instance that is neededmissing test records or accounts for {{consortium_namecount}} library.", "status_knowntesting_other": "We knoware about {{count}} Host LMS instances that are needed missing test records or accounts for {{consortium_namecount}}.", |
...
zero = the string rendered when there are 0 of count
...
one = the string rendered when there is 1 of count
...
libraries." |
In our code, we use the string without the underscore and number, and the string will automatically adapt to count.
Code Block | ||
---|---|---|
| ||
t(' |
...
status_ |
...
testing', {count: |
...
Here are examples of all keys which will be adapted:
Code Block | ||
---|---|---|
| ||
{
"key_zero": "zero",
"key_one": "singular",
"key_two": "two",
"key_few": "few",
"key_many": "many",
"key_other": "other"
} |
Multiple 'Counts'
...
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." |