dyna-gettext

A tiny npm modules that loads the text from static json files dynamically. Save your text in a json file. They key will be used as id of that text. Below is a text file. Save it as mytext.json.

Usage no npm install needed!

<script type="module">
  import dynaGettext from 'https://cdn.skypack.dev/dyna-gettext';
</script>

README

Dyna-gettext

A tiny npm modules that loads the text from static json files dynamically. Save your text in a json file. They key will be used as id of that text. Below is a text file. Save it as mytext.json.

{
    "hello" : {
        "en" : "Hello [name]",
        "fr" : "Bonjour [name]"
    },
}

You can can load this file in your app in following way

const dynatext = require('dyna-gettext');
dynatext.load(__dirname + '/mytext.json', 'mytext');

(async () => {
    let d = await dynatext.getText("hello", {id: 'mytext', lang: 'fr'}, {name: 'Nauroz'});
    console.log(d);
    //Bonjour Nauroz
})()