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: about 2 months ago
JSON representation

codemod to localize static strings

Lists

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", {}]]
});
```