babel-plugin-react-translate-maker
v0.0.2
Published
Automatic extraction of translations from modules that use react-translate-maker
Downloads
4
Maintainers
Readme
babel-plugin-react-translate-maker
This is a Babel plugin for automatic extraction of translations from modules that use react-translate-maker.
Note: Now requires babel 6
What?
It will create:
[
{
"path": "user.hello",
"defaultValue": "Hi {$user.name}"
},
{
"path": "header.navigation2.quizzes",
"defaultValue": "Quizzes",
"description": "Menu item"
},
{
"path": "header.navigation.minies",
"defaultValue": "Minies"
}
]
from:
import React, { Component } from 'react';
import Translate, { Namespace, LocaleProvider } from 'react-translate-maker';
export default class Test extends Component {
static contextTypes = {
...LocaleProvider.childContextTypes,
};
render() {
const { t } = this.context;
t('user.hello', 'Hi {$user.name}');
return (
<header>
<Namespace path="header.navigation">
<ul className="nav navbar-nav">
<li>
<Namespace path="header.navigation2">
<Translate path="quizzes" defaultValue="Quizzes" description="Menu item"/>
</Namespace>
</li>
<li>
<Translate path="minies" defaultValue="Minies"/>
</li>
</ul>
</Namespace>
</header>
);
}
}
Installation
$ npm install babel-plugin-react-translate-maker
Support us
Star this project on GitHub.
Usage
.babelrc
{
"plugins": [
["react-translate-maker", {
"filename": "locales.json"
}]
]
}
Options
- disableTFunction (Boolean = false): Disable to process t function
- moduleName (String = 'react-translate-maker'): Custom module name in node_modules
- path (String = './'): Path where do you want to save extracted locales.
- filename (String): Name of the file whitch will contain all extracted data. Only one file will be generated for all modules. Filename is working with path.
- suffix (String = '_locales.json'): Suffix of the generated files. This suffix is used only if option filename is undefined.
Running Tests
To run the test suite, first invoke the following command within the repo, installing the development dependencies:
npm install
Then run the tests:
npm test