1.2.0 • Published 6 years ago

intl-format v1.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

intl-format

I18N tools for universal javascrit apps, easy use & better api;

How To Use

Init this I18N tools

import IntlFormat from 'intl-format';

const intlFormat = IntlFormat.init('en-UK', {
  'en-UK': {
    test: 'testvalue',
    testTemplate: 'you have {value} unread message',
    photo: "You have {num, plural, =0 {no photos.} =1 {one photo.} other {# photos.}}"
  },
  'zh-CN': {
    lang: '语言'
  }
});

Then use it in your components

intlFormat.test; // testvalue;

intlFormat.get('test'); // testvalue;

intlFormat.get('testTemplate', {
  value: three
}); // value is 'you have three unread message'

intlFormat.template(intlFormat.testTemplate, {
  value: three
}); // value is 'you have three unread message'

intlFormat.get('photo', {
  num: 0
}); // value is 'You have no photos.'

How to change default language?

intlFormat.setLang('zh-cn'); // change the default language to zh-cn;

License

MIT