Skip to content

A simple translator for react loading languages from json file

License

Notifications You must be signed in to change notification settings

gasparteixeira/i18n-react-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

i18n-react-json

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.

About

A simple translator for react loading languages from json file

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published