https://github.com/springtype-org/st-i18n
~500 byte nano library for internationalization
https://github.com/springtype-org/st-i18n
Last synced: about 1 year ago
JSON representation
~500 byte nano library for internationalization
- Host: GitHub
- URL: https://github.com/springtype-org/st-i18n
- Owner: springtype-org
- License: mit
- Created: 2021-02-05T23:30:10.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-03-02T19:30:24.000Z (about 5 years ago)
- Last Synced: 2025-02-06T12:38:31.617Z (about 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 411 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
SpringType: st-i18n
Nano library for client-side translation
[](https://gitter.im/springtype-official/springtype?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
Purpose
This is an exremely tiny, yet powerful library for translation. `st-i18n` does also handle string interpolation for advanced translation needs.
Features
- ✅ 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
How to
This is how using `st-i18n` looks like:
```tsx
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}', {
name: 'Jack'
});
```
API
The following contract is made between the webapp and `st-i18n`:
```typescript
export interface API {
language: string;
defaultNamespace: string;
trans: Translations;
t: (namespace?: string) => TFunction;
load: (language: string, translations: NamespaceTranslation) => API;
}
```
Backers
Thank you so much for supporting us financially! 🙏🏻😎🥳👍
Maintainers
`st-i18n` is brought to you by:
Michael Mannseicher
Aron Homberg
Contributing
Please help out to make this project even better and see your name added to the list of our
[CONTRIBUTORS.md](./CONTRIBUTORS.md) :tada: