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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.228latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.228
1.0.10
1.0.00
1.0.0-beta20
1.0.0-beta10

Package Sidebar

Install

npm i intl-message

Weekly Downloads

28

Version

1.0.2

License

MIT

Unpacked Size

65.7 kB

Total Files

21

Last publish

Collaborators

  • alphakevin