st-i18n

    1.0.1 • Public • Published

    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: 'Jack'
    });

    API

    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;
    }

    Backers

    Thank you so much for supporting us financially! 🙏🏻😎🥳👍

    Tom

    Maintainers

    st-state 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 🎉

    Install

    npm i st-i18n

    DownloadsWeekly Downloads

    1

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    35.9 kB

    Total Files

    42

    Last publish

    Collaborators

    • springtype-org