Skip to content
Nizivo UI

I18n

The @nizivo/react/i18n entry.

Import

import { formatLabel } from '@nizivo/react/i18n';

Exports

LabelValues type

import type { LabelValues } from '@nizivo/react/i18n'

The values a label's placeholders read: {count} reads count.

type LabelValues = Readonly<Record<string, string | number>>

PluralCategory type

import type { PluralCategory } from '@nizivo/react/i18n'

The CLDR plural categories Intl.PluralRules can select.

type PluralCategory = "zero" | "one" | "two" | "few" | "many" | "other"

PluralLabel type

import type { PluralLabel } from '@nizivo/react/i18n'

A label with one template per CLDR plural category of its locale, other required. A locale lists exactly the categories Intl.PluralRules has 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>>

formatLabel function

import { formatLabel } from '@nizivo/react/i18n'

Fills a label. A PluralLabel picks its template by values.count, through new Intl.PluralRules(locale).select(values.count) (other when the category is missing or count is not a number); a plain string is used as is. Each {name} placeholder is replaced by values.name: a number formatted with Intl.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

On this page