1.0.6 • Published 7 years ago
i18n-react-json v1.0.6
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-jsonor
$ npm i i18n-react-jsonConfiguration
Lets create your files respository, for example: "locales"
|--project
|--public
|--src
|--locales
|-- en.json
|-- pt.jsonIn 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.