sg-i18n
A simple tool to translate i18n.
use
install
npm install sg-i18n -S
use
import I18n from 'sg-i18n';
let locale = 'zh-cn';
let localeData = {
"test": "test string",
"b.test": "test string b",
"a is b's father": "${a} is ${b}'s father",
"c": {
"test": "test string c"
}
}
let i18n = new I18n({
locale: 'zh-CN',
i18nData: {},
log: process.env.NODE_ENV !== 'production',
});
i18n.setLocaleData(locale, i18nData);
i18n.setLocale(locale);
let str = i18n.__('test');
let str = i18n.__('b.test');
let str = i18n.__('c.test');
let str = i18n.__('a is b\'s father', {
a: 'Json',
b: 'Joy'
});
api
i18n.setLocaleData(locale, localeData)
i18n.setLocale(locale)
i18n.translate(key, vars={})
i18n.__(key, vars={})
: alias to i18n.translate