# intl的icu插件

产出一个`ICU`插件和一个transform函数`IntlMessageFormat`。

```
export default ICU;
export {
  IntlMessageFormat
};
```

### Usage

```js
const IntlMessageFormat = require('../lib/intl-icu-plugin.cjs').IntlMessageFormat;

let map = {
    key: 'value',
    key2: 'value2',
    options: 'hello {value}',
    COST_TIME: "It took me {t, number} minutes to run yesterday",
    COUPON: "Coupon expires at {expires, time, medium}",
    PHOTO: "You have {photoNum, plural, =0 {no photos.} =1 {one photo.} other {# photos.}}",
    SALE_END: "Sale ends {end, date, long}",
    SALE_PRICE: "The price is {price, number, USD}"
}

function i18n(key, options, language) {
    const msg = new IntlMessageFormat(map[key], language);
    return msg.format(options);
}


console.log(i18n('key', {}, 'en'));
console.log(i18n('key2', {}, 'en'));
console.log(i18n('options', { value: 'starling '}, 'en'));
console.log(i18n('COST_TIME', { t: 10 }, 'en'));
console.log(i18n('COUPON', { expires: new Date() }, 'en'));
console.log(i18n('PHOTO', { photoNum: 0 }, 'en'));
console.log(i18n('PHOTO', { photoNum: 1 }, 'en'));
console.log(i18n('PHOTO', { photoNum: 2 }, 'en'));
console.log(i18n('SALE_END', { end: new Date() }, 'en'));
console.log(i18n('SALE_PRICE', { price: 10000 }, 'en'));


// value
// value2
// hello starling 
// It took me 10 minutes to run yesterday
// Coupon expires at 7:07:52 PM
// You have no photos.
// You have one photo.
// You have 2 photos.
// You have no photos.
// Sale ends August 19, 2020
// The price is 10,000
```

### Feature

1.0.12 更新：

- fix：在插值参数丢失的情况下，不会使页面 crash，而是会用空字符串代替并发出控制台警告