@react-translate/core
TypeScript icon, indicating that this package has built-in type declarations

3.3.6 • Public • Published

React Translate

The core library for React Translate.

Shields.io badge

The latest distribution files can be found on UNPKG:

Installation

npm i --save @react-translate/core

Usage

At the root of your app, set up your localization context provider:

import React, { useState } from 'react';
import { Languages, Locales, LocalizationContext } from '@react-translate/core';

const App = () => {
    const [currentLanguage, setCurrentLanguage] = useState<Languages>(Languages.en);
    const [currentLocale, setCurrentLocale] = useState<Locales>(Locales.enUS);

    return (
        <LocalizationContext.Provider value={{
            language: currentLanguage,
            locale: currentLocale,
            update: (language: Languages, locale?: Locales) => {
                setCurrentLanguage(language);
                setCurrentLocale(locale);
            }
        }}>
            ...
        </LocalizationContext.Provider>
    )
}

You can then use the Translate component which will update it's translation whenever LocalizationContext's language property is updated.

import React, { useContext } from 'react';
import Translate from '@react-translate/core';

const MyComponent = () => {
    return (
        <div>
            <Translate en="Hello" es="Hola" de="Guten Tag" fr="Bonjour" it="Salve" ru="Zdravstvuyte" />
        </div>
    )
}

Contributing

Contributing Guide

Please read our contributing guide for information on how to suggest code changes.

Code of Conduct

We encourage you to read our code of conduct to know what is and isn't tolerated by interacting with our repository.

License

React Translate is GPL-3.0 licensed.

/@react-translate/core/

    Package Sidebar

    Install

    npm i @react-translate/core

    Weekly Downloads

    7

    Version

    3.3.6

    License

    GPL-3.0

    Unpacked Size

    116 kB

    Total Files

    29

    Last publish

    Collaborators

    • matthewdowns