babel-plugin-mickey-i18n
Extract i18n message files and replace text with i18n-formatter.
React Intl is awesome. But, defineMessages is hard-coding, also Global ID management is difficult and confusing.
This plugin releases you from tedious codings, helps you building react components without any perceptions of i18n.
Take a look at the following component:
import React from 'react'; Component { ; thishello = '你好'; thistemplate = `你好,` } state = hello: '你好' name: '小明' { const hello name = thisstate; return <div ="小明,你好"> <p>name,hello</p> <p>小明,你好</p> </div> ; }
Compiled with this plugin, result that all the Chinese characters in this component ware replaced with _i18n
mathod which exported from mickey-i18n(the client for localized messages):
import i18n as _i18n from "mickey-i18n";import React from 'react'; Component { ; thishello = ; thistemplate = } state = hello: name: { const hello name = thisstate; return <div => <p>name,hello</p> <p></p> </div> ; }
We also get a message file like this, the id is the text's hashcode:
Then we can use atool-l10n to automatically generate localization resource.
Install
npm install babel-plugin-mickey-i18n --save-devnpm install mickey-i18n react react-dom react-intl --save
Usage
Add the following section in your .babelrc:
Options
dest
The target directory of message file. Default:./i18n_messages
filename
The target file name of message file. Default:i18n.json
debug
Iftrue
we will get message files of each component. Default:false
Contributing
Pull requests and stars are highly welcome.
For bugs and feature requests, please create an issue.