Logo
Chakra-UIReactJsNext.JS
Head

@codecraftkit

Documentation

useTranslate

Description#

The useTranslate is used to change the text language, when the language selected changes.

Installation#

Code Example

npm i @codecraftkit/usetranslate

Import#

it can be imported from hooks.

Code Example

import { useTranslate } from "@codecraftkit/hooks";

or alone.

Code Example

import { useTranslate } from "@codecraftkit/usetranslate";

Usage#

This hook allows you to make a text change depending on the language selected

Code Example

function MyApp() {
const translate = useTranslate()
return <>
<Text>{translate("LIGHT_MODE")}</Text>
</>
}

Adding New Words#

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

    lang en configlang es config
  • Example

    Code Example

    function MyApp() {
    const translate = useTranslate()
    return <>
    <Text>{translate("LIGHT_MODE")}</Text>
    </>
    }

Arguments#

It doesn't take any arguments

Results#

name

type

description

translate

Function

Function that receive a language variable previously saved in the language configuration