Skip to content

springtype-org/st-i18n

Repository files navigation

SpringType: st-i18n

Nano library for client-side translation

Gitter

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:

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:

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 🎉

About

~500 byte nano library for internationalization

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published