J
J
Jedi2020-02-17 17:28:55
Internationalization and localization
Jedi, 2020-02-17 17:28:55

How to link Redux and i18n?

Hello!

How to implement a bunch of Redux and i18n?

i18n is a library for implementing application localization (multilingualism).

When the user logs in, we must tell this library via dispatch that the user has a different language.

How to do it?

Here is the main i18n config file:

import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import React from "react";

// the translations
// (tip move them in a JSON file and import them)
const resources = {
    en: {
        translation: {
            "Главная": "Homepage",
        }
    }
};

i18n
    .use(initReactI18next) // passes i18n down to react-i18next
    .init({
        resources,
        lng: "en",

        keySeparator: false, // we do not use keys in form messages.welcome

        interpolation: {
            escapeValue: false // react already safes from xss
        }
    });

export default i18n;


We include this file in App.js (index.js).

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question