@coherent.js/i18n
v1.1.2
Published
Internationalization support for Coherent.js applications
Downloads
776
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 { createTranslator, createFormatters, createLocaleManager } 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';
const translator = createTranslator({ defaultLocale: 'en' });
translator.addTranslations('en', { hello: 'Hello, {{name}}!' });
translator.addTranslations('fr', { hello: 'Bonjour, {{name}} !' });
console.log(translator.t('hello', { name: 'Coherent' })); // Hello, Coherent!
translator.setLocale('fr');
console.log(translator.t('hello', { name: 'Coherent' })); // Bonjour, Coherent !TypeScript:
import { createTranslator } from '@coherent.js/i18n';
const translator = createTranslator({ defaultLocale: 'en' });
translator.addTranslations('en', { hello: 'Hello, {{name}}!' });
console.log(translator.t('hello', { name: 'TS' }));Formatters and locale
import { createFormatters, createLocaleManager } from '@coherent.js/i18n';
const locales = createLocaleManager({ defaultLocale: 'en-US' });
const fmt = createFormatters(locales.getLocale());
fmt.date.format(new Date()); // 1/15/2026
fmt.number.format(12345.678); // 12,345.678
fmt.currency.format(1999.99); // $1,999.99Exports
@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
