1.0.2 • Published 2 years ago

react-translation.js v1.0.2

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
2 years ago

react-translation.js

A translation library to help react applications managing, loading and applying translations.

Usage

Simple example of translation

Add context on top of page

import TranslationJSContext from "react-translation.js"
ReactDOM.render(<React.StrictMode><TranslationJSContext><App/></TranslationJSContext></React.StrictMode>, document.getElementById("root"))

Add translation

import  { LoadTrans, useTranslation } from 'react-translation.js'
const translation = useTranslation();
LoadTrans("pt", { global: { missing: { text: "Texto em Falta" } } }, translation, true)

Use translation

import  { T } from 'react-translation.js'
T("global.missing.text")

T will return o em Falta

You can also directly load a JSON.parse() into the LoadTrans function

Development

To build the library all you have to do is run the following commands

  yarn
  yarn build