Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amerani/babel-plugin-localize
codemod to localize static strings
https://github.com/amerani/babel-plugin-localize
babel codemod localization
Last synced: 3 days ago
JSON representation
codemod to localize static strings
- Host: GitHub
- URL: https://github.com/amerani/babel-plugin-localize
- Owner: amerani
- License: mit
- Created: 2018-07-07T20:36:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-21T03:24:51.000Z (over 6 years ago)
- Last Synced: 2024-04-26T20:47:19.056Z (6 months ago)
- Topics: babel, codemod, localization
- Language: JavaScript
- Homepage:
- Size: 266 KB
- Stars: 10
- Watchers: 4
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
- awesome-codemods - babel-plugin-localize - Codemod to localize static strings. (Misc / ant-design)
- awesome-babel - localize - Modify static jsx text and string attributes with function call. 🔧 (Plugins / Internationalization)
README
# babel-plugin-localize
modify static strings in jsx code to localization friendly formats## example
input
```jsx
const jsxText = (
<>
hello world
hello world
>
);
const jsxAttribute = (
);```
output
```jsx
import { localize } from './localizer';const jsxText = (
<>
{localize("loc_0")}
hello world
>
);
const jsxAttribute = (
);export const localizeKeyMap = {
"loc_0": "hello world",
"loc_1": "awesome"
};
```## options
```json
{
"elementsReplaceStringAttributes": {
"Title": ["name"]
},
"elementsPreserveJsxText": {
"Static": true
},
"keyPrefix": "loc_",
"keyType": "serial",
"localizer": "localize",
"localizerBinding": "named",
"localizerSource": "./localizer",
"keyMapIdentifier": "localizeKeyMap"
}
```## installation
npm
```sh
npm install --save-dev babel-plugin-localize
```
yarn
```sh
yarn add -D babel-plugin-localize
```## usage
### via `.babelrc` (Recommended)
**.babelrc**
```json
{
"plugins": [["localize", {}]]
}
```### via CLI
```sh
babel --plugins localize script.js
```### via Node API
```javascript
require("@babel/core").transform("code", {
plugins: [["localize", {}]]
});
```