Plurals
Plural translations work out of the box without any external dependencies, using the Intl.PluralRules (opens in a new tab) API, which is supported in all browsers and Node.js.
To declare plural translations, append # followed by zero, one, two, few, many or other:
// locales/en.ts
export default {
'cows#one': 'A cow',
'cows#other': '{count} cows'
} as constThe correct translation will then be determined automatically using a mandatory count parameter. The value of count is determined by the union of all suffixes, enabling type safety:
zeroallows 0oneautocompletes 1, 21, 31, 41... but allows any numbertwoautocompletes 2, 22, 32, 42... but allows any numberfew,manyandotherallow any number
This works in both Client and Server Components, and with scoped translations:
export default function Page() {
const t = useI18n()
return (
<div>
{/* Output: A cow */}
<p>{t('cows', { count: 1 })}</p>
{/* Output: 3 cows */}
<p>{t('cows', { count: 3 })}</p>
</div>
)
}