0.0.8 • Published 5 years ago

babel-plugin-string-to-intl v0.0.8

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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
0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago