intl-format
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i intl-format

Weekly Downloads

31

Version

1.2.0

License

MIT

Last publish

Collaborators

  • linhuiwu