react-intl-json-macro
v1.0.5
Published
When creating new keys for react-intl elements in your application, this package allows users to enter new key:value into CLI to write to react-intl json files and sort.
Downloads
11
Maintainers
Readme
react-intl-macro-json
npm package
When creating new keys for react-intl elements in your application, this package allows users to enter new key:value into CLI to write to react-intl json files and sort.
Install
npm install react-intl-json-macro
Setup
- In your
package.json
, add a script similiar to the following:
"scripts": {
"add:intlMessage": "node node_modules/react-intl-json-macro [JSON file directory location]"
}
- For example:
"add:intlMessage": "node node_modules/react-intl-json-macro './src/i18n/locales'"
- Only JSON files will be selected from the defined directory
Running Tool
npm run add:intlMessage "KEY NAME" "MESSAGE NAME"
For example:npm run add:intlMessage "header.subText" "default message text"
- All JSON files in the directory you have defined in the npm scripts will then be updated with the key:value pair you have executed. All keys in each JSON file will be alphabetized after the new key:value pair has been added.
Additional Notes
- Installing Prettier will help keep the JSON files formatted nicely
- Install: `npm install --save-dev prettier
- Update npm scripts for prettier
"scripts": {
"pretty:json": "prettier --write './src/i18n/locales/*.json'"
}
- Run scripts together now
npm run add:intlMessage "header.subText" "default message text" && npm run pretty:json