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

1.0.2 • Public • Published

intl-message

NPM Version

Simple intl message translation

Install

npm i intl-message
# or 
yarn add intl-message

Usage

See hello world example

Add command line tool to package.json

{
  //...
  "script": {
    "intl:extract": "intl-extract"
  }
  //...
}

Extracting Messages from Source Code

yarn intl:extract

Source Code

intl.js

import { Intl } from 'intl-message';
const intl = new Intl({
  en: require('./locales/en.json'),
  'zh-cn': require('./locales/zh-cn.json'),
});
export default intl;
export const __ = (...params) => intl.formatMessage(...params);

app.js

import intl, { __ } from './intl';
console.log(__({ id: 'hello', defaultMessage: 'Hello, World!' }));
// Hello, World!
intl.language = 'zh-cn';
console.log(__({ id: 'hello' }));
// [en]Hello, World!

Update Dictionary

Edit locales/zh-ch.json

{
  "hello": "你好,世界!"
}

Run app.js again:

Hello, World!
你好,世界!

Licence

MIT

Readme

Keywords

Package Sidebar

Install

npm i intl-message

Weekly Downloads

6

Version

1.0.2

License

MIT

Unpacked Size

65.7 kB

Total Files

21

Last publish

Collaborators

  • alphakevin