An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

SpringType: st-i18n


Nano library for client-side translation

[![Gitter](https://badges.gitter.im/springtype-official/springtype.svg)](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! 🙏🏻😎🥳👍






Tom


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: