This repository was archived by the owner on Apr 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 182
Doc: Pluralization
James Alexander Rosen edited this page Jun 24, 2015
·
1 revision
Ember-i18n includes support for inflection based on a count interpolation. Pluralization rules are based on the Unicode Common Locale Data Repository.
Whenever you pass the count option to the t function, template will be pluralized:
// app/locales/en/translations.js:
export default {
'dog': {
'one': 'a dog',
'other': '{{count}} dogs'
}
};
// Elsewhere:
i18n.t('dog', { count: 1 }); // a dog
i18n.t('dog', { count: 2 }); // 2 dogsember-i18n converts 1 to .one and 2 to .other. Depending on the locale, there could be up to 6 plural forms used: zero, one, two, few, many, other.
If you want to override the inflection rules for a locale, you can define your own in app/locales/[locale]/config.js. For example, to add support for zero to English:
// app/locales/en/config.js:
export default {
pluralForm: function englishWithZero(n) {
if (n === 0) { return 'zero'; }
if (n === 1) { return 'one'; }
return 'other';
}
}