sahara-localization
v0.1.2
Published
npm install --save sahara-localization
Downloads
3
Readme
Installation
npm install --save sahara-localization
Usage
import _, {setLocalizations} from 'sahara-localization';
setLocalizations({
en: {
'hello': 'hello',
'hello %s': 'hello %s',
'%s has %s post': '%s has %s post',
'%s has %s posts': '%s has %s posts'
},
es: {
'hello': 'hola',
'hello %s': 'hola %s',
'%s has %s post': '%s tiene %s posta',
'%s has %s posts': '%s tiene %s puestos'
}
});
console.log(_('test', 'test')); // test
console.log(_('en', 'hello')); // hello
console.log(_('es', 'hello')); // hola
console.log(_('en', 'hello %s', 'John')); // hello John
console.log(_('es', 'hello %s', 'John')); // hola John
var postCount = 1;
console.log(_('en', ['%s has %s post', '%s has %s posts', () => postCount > 1 ? 1 : 0], 'John', postCount)); // John has 1 post
var postCount = 2;
console.log(_('es', ['%s has %s post', '%s has %s posts', () => postCount > 1 ? 1 : 0], 'John', postCount)); // John tiene 2 puestos