babel-plugin-string-to-intl

0.0.8 • Public • Published

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

  1. It is not working with complex JSXText
  2. 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:

  1. Go to Preferences -> External Tools -> Click plus to add tool.
  2. 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
  1. Open file you want to transform Right Click -> External Tools -> Formatted Message -> Apply prettier/code formatting -> Enjoy
  2. For even better experience go to. Preferences -> Keymap -> External Tools -> External Tools -> Formatted Message -> Attach some key combination

VS Code:

  1. Open command pallete
  2. >Tasks: Configure Task
  3. Press Up -> Select: Task from tasks.json template (or something like that)
  4. 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}"
        }
    ]
}
  1. Open command pallete and ask it to open keybindings.json
  2. Add this:
    {
        "key": "cmd+e",
        "command": "workbench.action.tasks.runTask",
        "args": "Formatted Message"
    }
  1. Open any file and press cmd+e to apply codemod on file.
  2. 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)
  3. Apply formatting and enjoy

Readme

Keywords

Package Sidebar

Install

npm i babel-plugin-string-to-intl

Weekly Downloads

1

Version

0.0.8

License

MIT

Unpacked Size

30.4 kB

Total Files

5

Last publish

Collaborators

  • igordolzh