1.3.3 • Published 4 years ago

com.siteblade.intl v1.3.3

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago
com.siteblade.intl

This package provides assets-based message translation.

Getting started

import { Translator } from 'com.siteblade.intl';

const translator = new Translator({
    assets: {
        // URL or path for resource loading
        path: 'path/to/res/lang',

        // configure JSON files for resource loading under assets.path option
        roots: ['common', 'validation'],

        // whether to clean assets automatically.
        clean: true,

        // 'fileSystem' or 'http'
        loaderType: 'fileSystem',
    }
});

(async () => {

    await translator.setLanguage('en-us');
})();

import { Gender } from 'com.siteblade.intl';

const t = translator.t.bind(translator);

console.log(t('common.messageId'));
console.log(t('common.parameterized', { x: 'foo' }));
console.log(t('common.contextual', Gender.MALE));
console.log(t('common.quantified', 10));

Example resource:

{
    "messageId": "Some message",
    "parameterized": "Here: $x",
    "contextualMale": "Male message",
    "contextualMale": "Female message",
    "quantifiedEmpty": "$amount: empty",
    "quantifiedSingle": "$amount: single",
    "quantifiedPlural": "$amount: plural"
}

Clone

When cloning Translator instances, it's recommended to set the assets.clean option to false.

To clone a Translator, you can use the Translator.clone() method, which will return an object that shares the same asset storage with the original object:

var tClone = translator.clone();

State extraction

let state = translator.getState();
translator.setState(state);
1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

0.1.0-alpha.0

4 years ago