@lionrapid/formatters
v0.1.0
Published
Advanced text formatters for LionRapid localization library
Maintainers
Readme
@lionrapid/formatters
ICU MessageFormat plugin for LionRapid. Adds pluralization, select, date/time, number, and currency formatting to translations.
Installation
npm install @lionrapid/formatters @lionrapid/coreUsage
import { LionRapidBuilder, MemoryRepository, NetworkRepository } from '@lionrapid/core';
import { CoreFormattersPlugin } from '@lionrapid/formatters';
const lionRapid = await LionRapidBuilder.init({
defaultLocale: 'en',
namespace: 'app',
})
.use(new MemoryRepository({ enabled: true }))
.use(new NetworkRepository({
enabled: true,
options: { baseUrl: 'https://api.lionrapid.com' },
}))
.use(new CoreFormattersPlugin())
.build();
// Pluralization
lionRapid.t('items', { count: 5 });
// Translation: "{count, plural, one {# item} other {# items}}"
// Output: "5 items"
// Select
lionRapid.t('greeting', { gender: 'female' });
// Translation: "{gender, select, male {He} female {She} other {They}}"
// Output: "She"
// Currency
lionRapid.t('price', { amount: 99.99 });
// Translation: "{amount, number, currency}"
// Output: "$99.99"
// Date
lionRapid.t('today', { date: new Date() });
// Translation: "Today is {date, date, long}"
// Output: "Today is January 15, 2026"Supported Formatters
| Formatter | ICU Pattern | Example |
|-----------|-------------|---------|
| Interpolate | {name} | Hello, John |
| Plural | {count, plural, ...} | 5 items |
| Select | {gender, select, ...} | She |
| Number | {val, number} | 1,234.56 |
| Currency | {val, number, currency} | $99.99 |
| Percent | {val, number, percent} | 75% |
| Date | {val, date, short} | 1/15/26 |
| Time | {val, time, medium} | 3:30 PM |
| Uppercase | {val, uppercase} | HELLO |
| Lowercase | {val, lowercase} | hello |
| Capitalize | {val, capitalize} | Hello |
License
MIT
