https://github.com/vimeo/babel-plugin-transform-i18n
A Babel transform plugin to replace strings with their translations.
https://github.com/vimeo/babel-plugin-transform-i18n
Last synced: 9 months ago
JSON representation
A Babel transform plugin to replace strings with their translations.
- Host: GitHub
- URL: https://github.com/vimeo/babel-plugin-transform-i18n
- Owner: vimeo
- License: mit
- Created: 2016-09-20T16:17:48.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-03-13T06:56:48.000Z (almost 3 years ago)
- Last Synced: 2024-09-20T09:20:03.607Z (over 1 year ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 10
- Watchers: 13
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# babel-plugin-transform-i18n [](https://travis-ci.org/vimeo/babel-plugin-transform-i18n) [](https://codecov.io/gh/vimeo/babel-plugin-transform-i18n) [](https://www.npmjs.com/package/@vimeo/babel-plugin-transform-i18n) [](https://gitter.im/vimeo/babel-plugin-transform-i18n)
A [Babel](https://babeljs.io) transform plugin to replace strings with their translations.
## Example
**.babelrc**
```json
{
"plugins": [
["transform-i18n", {
"dictionary": {
"Hello": "Bonjour",
"Hello, {name}!": "Bonjour, {name}!"
}
}]
]
}
```
**In**
```js
const name = 'Brad';
const hello = t('Hello');
const helloWithName = t('Hello, {name}!', {
name
})
```
**Out**
```js
const name = 'Brad';
const hello = 'Bonjour';
const helloWithName = 'Bonjour, ' + name + '!';
```
## Installation
```bash
npm install babel-plugin-transform-i18n
```
## Usage
### Via `.babelrc`
```json
{
"plugins": [
["transform-i18n", {
"functionName": "t",
"dictionary": {}
}]
]
}
```
### Via Node API
```js
require('babel-core').transform('code', {
plugins: [
['transform-i18n', {
functionName: 't',
dictionary: {}
}]
]
});
```
## Options
There are two options available, both are optional:
### `dictionary`
A mapping of the strings passed to the translation function to their translated versions. If no dictionary is passed, calls to the translation function will be replaced with the original string.
### `functionName`
The name of the function that wraps the strings. Defaults to `t`.