Handle plurals, ordinals, and select expressions with locale-aware rules
Saykit provides powerful pluralization features that automatically adapt to language-specific plural rules using CLDR (Unicode Common Locale Data Repository) standards.
Different languages have different plural rules. Saykit supports all six CLDR plural categories:
zero: Used in some languages for zero items (Arabic, Latvian)
one: Singular form (most languages)
two: Dual form (Arabic, Hebrew)
few: Small quantities (Polish, Russian, Czech)
many: Large quantities (Polish, Russian)
other: Default/fallback (always required)
English only uses one and other, but languages like Arabic use all six categories. Saykit automatically selects the correct form based on the active locale.
Use say.plural() to create messages that adapt to quantity:
import { say } from './i18n';function CartSummary({ count }: { count: number }) { return ( <div> {say.plural(count, { one: 'You have 1 item in your cart', other: 'You have # items in your cart', })} </div> );}
Different languages have different ordinal patterns:English: Uses one (1st, 21st), two (2nd, 22nd), few (3rd, 23rd), other (4th-20th)French: All ordinals use one for 1 (1er) and other for everything else (2e, 3e, 4e)Spanish: Similar to French, but uses different suffixes (1.º, 2.º, 3.º)
function OrderStatus({ status }: { status: string }) { return ( <div> {say.select(status, { pending: 'Your order is being processed', shipped: 'Your order is on its way', delivered: 'Your order has been delivered', cancelled: 'Your order was cancelled', other: 'Unknown order status', })} </div> );}
Unlike plural() and ordinal(), the selector in say.select() is a string, not a number. The # placeholder is not available in select expressions.
Plural, ordinal, and select expressions are automatically extracted:
say.plural(count, { one: 'You have # message', other: 'You have # messages',});
Generates in PO format:
msgid "{count, plural, one {You have # message} other {You have # messages}}"msgstr "{count, plural, one {You have # message} other {You have # messages}}"
Translators can then adapt the plural rules for their language while keeping the same code structure.