i18n-react-json
v1.0.6
Published
A simple translator for react loading languages from json file
Downloads
6
Maintainers
Readme
i18n-react-json
A simple translator for Reactjs load languages from json file.
Install
In your react project, run one of these commands:
$ yarn add i18n-react-json
or
$ npm i i18n-react-json
Configuration
Lets create your files respository, for example: "locales"
|--project
|--public
|--src
|--locales
|-- en.json
|-- pt.json
In the json file, for example:
// pt.json
{
"Hello" : "Olá",
"I am Gaspar": "Eu sou Gaspar"
}
Using it
In your App.js lets import and set the language.
//project/src/App.js
import Translate from "i18n-react-json";
import locales from "./locales";
// call tranlation
const i18n = new Translate(locales);
//set default language
i18n.setLocale("pt");
class App extends Component {
render() {
return (
<div className="App">
<p>{i18n.__("Hello")}, {i18n.__("I am Gaspar")}!</p>
</div>
);
}
export default App;
I also provided an example take a look or download it and run in your environment.