I18n
The @nizivo/react/i18n entry.
Import
import { formatLabel } from '@nizivo/react/i18n';Exports
LabelValuestypeimport type { LabelValues } from '@nizivo/react/i18n'The values a label's placeholders read:
{count}readscount.type LabelValues = Readonly<Record<string, string | number>>PluralCategorytypeimport type { PluralCategory } from '@nizivo/react/i18n'The CLDR plural categories
Intl.PluralRulescan select.type PluralCategory = "zero" | "one" | "two" | "few" | "many" | "other"PluralLabeltypeimport type { PluralLabel } from '@nizivo/react/i18n'A label with one template per CLDR plural category of its locale,
otherrequired. A locale lists exactly the categoriesIntl.PluralRuleshas for it (en-US:one,other; pl:one,few,many,other). Exact-number keys ('=0') are not supported.type PluralLabel = { other: string; } & Partial<Record<Exclude<PluralCategory, "other">, string>>formatLabelfunctionimport { formatLabel } from '@nizivo/react/i18n'Fills a label. A
PluralLabelpicks its template byvalues.count, throughnew Intl.PluralRules(locale).select(values.count)(otherwhen the category is missing orcountis not a number); a plain string is used as is. Each{name}placeholder is replaced byvalues.name: a number formatted withIntl.NumberFormat(locale), a string as written. A placeholder with no value stays as written:formatLabel('+{count}', { count: 1200 })is'+1,200'.function formatLabel(template: string | PluralLabel, values?: LabelValues, locale?: string): string