1.0.2 • Published 5 years ago
intl-message v1.0.2
intl-message
Simple intl message translation
Install
npm i intl-message
# or
yarn add intl-message
Usage
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!
你好,世界!