babel-plugin-string-to-intl
v0.0.8
Published
This plugin transforms string/jsxText/templates into react-intl FormattedMessage
Downloads
3
Readme
babel-plugin-string-to-intl
It's codemod for updating strings/jsxText/templates to from 'react-intl'
Usage
Install babel-codemod npm i -g babel-codemod
Then install in root of your project npm install babel-plugin-string-to-intl
Run it like that from node_modules hence:
codemod --plugin ./node_modules/babel-plugin-string-to-intl/src/index.js ./src
Also you may like to pretty print it using prettier instead of recast
codemod --plugin ./node_modules/babel-plugin-string-to-intl/src/index.js ./src --printer prettier
Remove babel-plugin-string-to-intl
from package.json
If there is any issues, let me know in the issues tab here at GitHub.
Limitations
- It is not working with complex JSXText
- It couldn't understand tech constants
Integration with WebStorm/VS Code to do file by file
Preconditions:
npm i -g babel-core babel-codemod babel-plugin-string-to-intl
WebStorm:
- Go to Preferences -> External Tools -> Click plus to add tool.
- Config:
Name: h to JSX
Program: codemod
Arguments: -p /usr/local/lib/node_modules/babel-plugin-string-to-intl/src/index.js$FilePathRelativeToProjectRoot$
Working directory: $ProjectFileDir$
In advanced settings:
Tick on: Sync file after execution
- Open file you want to transform
Right Click -> External Tools -> Formatted Message -> Apply prettier/code formatting -> Enjoy
- For even better experience go to.
Preferences -> Keymap -> External Tools -> External Tools -> Formatted Message -> Attach some key combination
VS Code:
- Open command pallete
>Tasks: Configure Task
- Press Up -> Select:
Task from tasks.json template
(or something like that) - Copy and paste this:
{
"version": "0.0.4",
"tasks": [
{
"label": "Formatted Message",
"type": "shell",
"command": "codemod -p /usr/local/lib/node_modules/babel-plugin-string-to-intl/src/index.js ${file}"
}
]
}
- Open command pallete and ask it to open
keybindings.json
- Add this:
{
"key": "cmd+e",
"command": "workbench.action.tasks.runTask",
"args": "Formatted Message"
}
- Open any file and press cmd+e to apply codemod on file.
- Or if you don't want to bloat your
keybindings.json
just open Command pallete and type.Run task -> Enter -> Find in the list "Formatted Message" -> Enter
(Usually will be on top) - Apply formatting and enjoy