@codecraftkit
Documentation
The useTranslate is used to change the text language, when the language selected changes.
In order to use it, you have to make sure to set the react-translate context first
This hook is based on React Translate
npm i @codecraftkit/usetranslate
it can be imported from hooks.
import { useTranslate } from "@codecraftkit/hooks";
or alone.
import { useTranslate } from "@codecraftkit/usetranslate";
This hook allows you to make a text change depending on the language selected
function MyApp() {const translate = useTranslate()return <><Text>{translate("LIGHT_MODE")}</Text></>}
In order to add a new custom word follow the next steps,
First have to go to the constant folder in the src directory
Inside the folder we'll find to js files, lang_en.js
and lang_es.js
, if they are not there, then you'll have to check if the project has the react-translate context if it doesn't that means the project is not configure to use translations yet
The file's structure look like this, here you can add any language variable, it must have the same name in both lang_en.js
and lang_es.js
files, in order to make the change
Example
function MyApp() {const translate = useTranslate()return <><Text>{translate("LIGHT_MODE")}</Text></>}
It doesn't take any arguments
translate
Function
Function that receive a language variable previously saved in the language configuration