modular-intl

0.0.4-beta.2 • Public • Published

modular-intl

Modular plan to manage international locale files. 国际化多语言文件的模块化管理方案。

Build Status Coverage Status npm npm

Install

Install By:

npm i --save modular-intl

Then import it by:

import { Application } from 'modular-intl';

Usage

You can create Application by the API provided by modular-intl.

import { Application } from 'modular-intl';
 
// create app with current locale language
const app = new Application('name', 'en_US');
 
// change locale
app.setDefaultLocale('zh_CN');
 
// create your modules
const m1 = app.createModule('m1');
 
// add locale language
m1.addLocale('zh_CN', {
  "excel": "电子表格",
});
m1.addLocale('en_US', {
  "excel": "Excel",
});
 
const m2 = app.createModule('m2');
// ...
 
 
// Get i18n text
const text = m1.get('excel');

Customize intl

You can customize your own intl function, e.g.

import { Application } from 'modular-intl';
import IntlMessageFormat from 'intl-messageformat';
 
// custom intl with intl-messageformat
const intl = (locales, currentLocale, ns, key, ...opts) =>
  new IntlMessageFormat(locales[key], currentLocale).format(opts[0]);
 
const app = new Application('name', 'en_US', intl);
 
const m1 = app.createModule('m1');
// ...
 
// use new intl with format opt
const text = m1.get('excel', { count: 100 });

Then you can use the formatter of intl-messageformat.

See more demo code here.

License

ISC@hustcc.

Package Sidebar

Install

npm i modular-intl

Weekly Downloads

2

Version

0.0.4-beta.2

License

ISC

Unpacked Size

11.3 kB

Total Files

7

Last publish

Collaborators

  • atool