st-i18n
v1.0.1
Published
Nano library for client-side translation
Downloads
6
Maintainers
Readme
This is an exremely tiny, yet powerful library for translation. st-i18n
does also handle string interpolation for advanced translation needs.
- ✅ Implements a simple, i18next-like API including string interpolation
- ✅ Comes with namespace support
- ✅ Tiny:
441 bytes
(best, brotli) -599 bytes
(worst, umd, gz) - ✅ Zero dependencies
- ✅ First class TypeScript support
- ✅ 100% Unit Test coverage
This is how using st-i18n
looks like:
import { tsx, render, Ref } from 'springtype';
import { $ } from 'st-query';
import { i18n } from 'st-i18n';
// example with local translation source
import de from './assets/translation/de.json';
import en from './assets/translation/en.json';
const t = i18n.t(/* optional: provide a namespace name here */);
/**
* de.json:
* e.g.:
* {
* "translation": {
* "Hello world, {name}": "Hallo {name}, Welt!"
* }
* }
*/
i18n.load('de', de);
i18n.load('en', en);
i18n.language = 'de';
// prints: Hallo Jack, Welt!
t('Hello world', {
name: 'Jack'
});
The following contract is made between the webapp and st-i18n
:
export interface API {
language: string;
defaultNamespace: string;
trans: Translation;
t: (ns?: string) => TFunction;
load: (language: string, ns: Namespace) => API;
}
Thank you so much for supporting us financially! 🙏🏻😎🥳👍
st-state
is brought to you by:
Please help out to make this project even better and see your name added to the list of our CONTRIBUTORS.md :tada: