A zero-dependency (for the forseen future hopefully), typescript-ready, fast, lightweight and, of course, shrimple package to localize your projects.
First get your locale files going. A json file is enough:
// en.json
{
"salutes": {
"hello": "Hello",
"goodbye": "Goodbye"
},
"world": "World"
}
// es.json
{
"salutes": {
"hello": "Hola",
"goodbye": "AdiĆ³s"
},
"world": "Mundo"
}
Then, you can use the package like this:
import { Localization } from 'shrimple-locales';
import enLocale from './en.json';
import esLocale from './es.json';
const loc = new Localization({
defaultLocale: 'en',
fallbackLocale: 'en',
locales: {
en: enLocale,
es: esLocale,
},
});
// ... later in the code
foo(`${loc.get('salutes.hello')} ${loc.get('world')}`); // Hello World
loc.setLocale('es');
foo(`${loc.get('salutes.hello')} ${loc.get('world')}`); // Hola Mundo
localizationFor()
)