https://github.com/onigoetz/i18n
I18n Libraries and tools
https://github.com/onigoetz/i18n
i18n icu-messageformat intl l10n messageformat translation typescript
Last synced: about 1 year ago
JSON representation
I18n Libraries and tools
- Host: GitHub
- URL: https://github.com/onigoetz/i18n
- Owner: onigoetz
- License: mit
- Created: 2020-06-30T20:03:13.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-10T17:05:11.000Z (about 2 years ago)
- Last Synced: 2024-04-10T20:57:31.366Z (about 2 years ago)
- Topics: i18n, icu-messageformat, intl, l10n, messageformat, translation, typescript
- Language: TypeScript
- Homepage: https://onigoetz.github.io/i18n/
- Size: 14 MB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @onigoetz/i18n
[](https://github.com/onigoetz/i18n/releases)


[](https://sonarcloud.io/dashboard?id=onigoetz_i18n)
[](https://sonarcloud.io/dashboard?id=onigoetz_i18n)
[](https://www.npmjs.com/package/@onigoetz/messageformat)
A suite of packages to ease your translation needs.
## Packages
- `@onigoetz/messageformat` a MessageFormat parsing and rendering library
- `@onigoetz/make-plural` a lighter fork of `make-plural` meant for browser usage
- `@onigoetz/intl-formatters` default formatters if you don't already have formatters for dates and numbers, uses the standard `Intl` API
## Features
- Small, Fast and no NPM dependencies
- TypeScript ❤️
- Fully tested
- Flexible; Use one package, or two, bring your own formatters, or use the embedded ones, use on Node.js, or in the browser. You choose !
- ICU MessageFormat compatible
- CLDR compatible
## Example
```typescript
import { parse, createRenderer } from "@onigoetz/messageformat";
import {
dateFormatter,
numberFormatter,
pluralGenerator,
} from "@onigoetz/intl-formatters";
// Parse the MessageFormat to a renderable format
const parsed = parse("{test, plural, offset:3 one{one test} other {# test} }");
// Create a localized renderer
const render = createRenderer(
"en",
(locale: T, type) => pluralGenerator(locale, { type }),
(locale: T, options, value: number) =>
numberFormatter(locale, options)(value),
(locale: T, options, value: Date) => dateFormatter(locale, options)(value)
);
render(parsed, { test: 4 }); // => "one test"
render(parsed, { test: 7 }); // => "4 test"
```
## Who is the audience for this library ?
This library is meant for applications starting with medium scale, where you might have multiple libraries and frameworks inside.
Since these libraries don't make any assumption about your stack, you can integrate them in any kind of application.
Most importantly, if you have an environment where pre-compiling translations isn't possible,
for example because your translation build process is separate from your app build process or you have a modular application / microfrontend.
This library is very interesting as a lightweight runtime because of its small footprint and performant parsing.
## Inspiration
This suite of packages certainly wouldn't exist without the previous work in the field.
This package forked [`make-plural`](https://www.npmjs.com/package/make-plural) at version 4 to make it smaller.
Took inspiration for the MessageFormat parser from [`@ffz/icu-msgparser`](https://www.npmjs.com/package/@ffz/icu-msgparser)
for its small size and [`@phensley/messageformat`](https://www.npmjs.com/package/@phensley/messageformat) for its parsing speed.
## Building
- `yarn build`
- `yarn test`
## Linting
- `yarn format --write`
- `yarn check --apply`