@coherent.js/i18n
v1.0.0-beta.5
Published
Internationalization support for Coherent.js applications
Maintainers
Readme
@coherent.js/i18n
Internationalization utilities for Coherent.js applications.
- ESM-only, Node 20+
- Translator + locale management
- Date/number/currency/list formatters
For a high-level overview and repository-wide instructions, see the root README: ../../README.md
Installation
pnpm add @coherent.js/i18nExports
Internationalization utilities
Modular Imports (Tree-Shakable)
- i18n utilities:
@coherent.js/i18n
Example Usage
import { createI18n } from '@coherent.js/i18n';Note: All exports are tree-shakable. Import only what you need for optimal bundle size.
Quick start
JavaScript (ESM):
import { createTranslator } from '@coherent.js/i18n/translator';
const t = createTranslator({
en: { hello: 'Hello, {name}!' },
fr: { hello: 'Bonjour, {name} !' }
}, { locale: 'en' });
console.log(t('hello', { name: 'Coherent' }));TypeScript:
import { createTranslator } from '@coherent.js/i18n/translator';
type Messages = {
hello: string;
};
const t = createTranslator<{ en: Messages; fr: Messages }>({
en: { hello: 'Hello, {name}!' },
fr: { hello: 'Bonjour, {name} !' }
}, { locale: 'en' });
console.log(t('hello', { name: 'TS' }));Formatters and locale
import { createFormatters } from '@coherent.js/i18n/formatters';
import { createLocaleManager } from '@coherent.js/i18n/locale';
const locale = createLocaleManager('en-US');
const fmt = createFormatters(locale.current());
fmt.date(new Date());
fmt.number(12345.678);
fmt.currency(1999.99, 'USD');Exports
@coherent.js/i18n(index)@coherent.js/i18n/translator@coherent.js/i18n/formatters@coherent.js/i18n/locale
Development
pnpm --filter @coherent.js/i18n run test
pnpm --filter @coherent.js/i18n run test:watch
pnpm --filter @coherent.js/i18n run typecheckLicense
MIT © Coherent.js Team
