<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: shubham gupta</title>
    <description>The latest articles on DEV Community by shubham gupta (@shubham_gupta_6f6c50fefd4).</description>
    <link>https://dev.to/shubham_gupta_6f6c50fefd4</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3717498%2F1a289192-343b-40a1-88c4-2e0eaffc31d1.png</url>
      <title>DEV Community: shubham gupta</title>
      <link>https://dev.to/shubham_gupta_6f6c50fefd4</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shubham_gupta_6f6c50fefd4"/>
    <language>en</language>
    <item>
      <title>Adding Multi-Lingual Support in React</title>
      <dc:creator>shubham gupta</dc:creator>
      <pubDate>Sun, 18 Jan 2026 07:14:10 +0000</pubDate>
      <link>https://dev.to/shubham_gupta_6f6c50fefd4/adding-multi-lingual-support-in-react-i90</link>
      <guid>https://dev.to/shubham_gupta_6f6c50fefd4/adding-multi-lingual-support-in-react-i90</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0vktwx9gtcjx0788ha2a.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0vktwx9gtcjx0788ha2a.jpg" alt=" " width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To add multi-language support to your project, you need to implement internationalization in React. We use react-i18next, which is based on i18next.&lt;br&gt;
This module provides components to render translated content when the language changes. It can be used with any UI framework (Angular, React, Vue, etc.).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.i18next.com/" rel="noopener noreferrer"&gt;https://www.i18next.com/&lt;/a&gt; We will be using i18next in our React project. Localization and translation will be stored on the React side.&lt;/p&gt;

&lt;p&gt;To begin, install this package in your React project.Create a file named i18n.js that contains the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import i18n from "i18next";
import LanguageDetector from "i18next-browser-languagedetector";
import Backend from "i18next-xhr-backend";
import { initReactI18next } from "react-i18next";

const fallbackLng = ["en"];

i18n
  .use(Backend) // used to load data from othe directory
  .use(LanguageDetector) // detects the current language
  .use(initReactI18next) // passes i18n down to react-i18next
  .init({
    fallbackLng, // default language
    detection: {
      checkWhitelist: true,
    },
    debug: false,
    interpolation: {
      escapeValue: false, // no need for react. it escapes by default
    },
  });

export default i18n;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In your App.js import i18n.js file&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import "./i18n";&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In above code we have used LanguageDetector from react-i18next-browser-languagedetector which automatically detects the selected language, similarly we have used Backend from react-i18next-xhr-backend , to load our data .&lt;/p&gt;

&lt;p&gt;Here, we will be adding support for two languages English and French.&lt;/p&gt;

&lt;p&gt;Create a folder in your Public folder named locale , add another folder inside it named language code i.e "en" and"fr" each containing a file named translation.json&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2gpzo17unrm7xyiz0gls.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2gpzo17unrm7xyiz0gls.png" alt=" " width="417" height="417"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inside translation.json, the file contains key value pair, a unique key for that word, and its respective translation as its value. Here are some samples&lt;/p&gt;

&lt;p&gt;If you need to store your files in any other path than the default path u can specify the path while Initialization&lt;/p&gt;

&lt;p&gt;Example, here I have stored my files inside the assets folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;backend: {
      loadPath: "/assets/locale/{{lng}}/translate.json",
    },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside en/translation.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "hello": "Hello",
  "cancel": "Cancel",
  "continue": "Comtinue"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;fr/translation.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "hello": "Salut",
  "cancel": "Annuler",
  "continue": "Continuez"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, to use these translations in your application, we use the useTranslation hook from react-i18next.&lt;/p&gt;

&lt;p&gt;Mostly we will be using t function and i18n instance provided by the useTranslation hook.&lt;/p&gt;

&lt;p&gt;i18n instance provides a function changeLanguage() which accepts language code as to which language need to be rendered in our react application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Menu, Transition } from "@headlessui/react";
import { GlobeAltIcon } from "@heroicons/react/24/outline";
import { Fragment } from "react";
import { useTranslation } from "react-i18next";

function classNames(...classes) {
  return classes.filter(Boolean).join(" ");
}

let countries = [
  {
    code: "fr",
    name: "Français",
    country_code: "fr",
  },
  {
    code: "en",
    name: "English",
    country_code: "gb",
  },
];

const LanguageSelector = () =&amp;gt; {
  const { t, i18n } = useTranslation();

  return (
    &amp;lt;&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;Menu
          as="div"
          className="px-3 pl-0 relative flex"
          aria-label="usermenu"
        &amp;gt;
          &amp;lt;Menu.Button
            className="group w-full  text-sm text-left font-medium text-gray-700 focus:outline-none"
            aria-label="usermenu-button"
          &amp;gt;
            &amp;lt;span className="flex w-full justify-between items-center"&amp;gt;
              &amp;lt;GlobeAltIcon className="h-7 w-7 cursor-pointer  text-blue-600" /&amp;gt;
            &amp;lt;/span&amp;gt;
          &amp;lt;/Menu.Button&amp;gt;
          &amp;lt;Transition
            as={Fragment}
            enter="transition ease-out duration-100"
            enterFrom="transform opacity-0 scale-95"
            enterTo="transform opacity-100 scale-100"
            leave="transition ease-in duration-75"
            leaveFrom="transform opacity-100 scale-100"
            leaveTo="transform opacity-0 scale-95"
          &amp;gt;
            &amp;lt;Menu.Items
              aria-label="menu-item-container"
              className="z-10 mx-3 origin-top absolute left-[-36px] sm:left-[-25px] md:left-[-25px] top-[42px] xl:left-[-80px] right-0 min-w-max mt-1 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 divide-y divide-gray-200 focus:outline-none"
            &amp;gt;
              &amp;lt;div className="px-1 py-1 " aria-label="menu-items"&amp;gt;
                {countries.map((lng) =&amp;gt; {
                  return (
                    &amp;lt;Menu.Item key={lng.code}&amp;gt;
                      &amp;lt;button
                        className={classNames(
                          "flex items-center space-x-2 px-4 py-2 text-sm cursor-pointer"
                        )}
                        onClick={() =&amp;gt; i18n.changeLanguage(lng.code)} // used to change language that needs to be rendered
                        disabled={i18n.language === lng.code}
                      &amp;gt;
                        &amp;lt;span class={`fi fi-${lng.country_code}`}&amp;gt;&amp;lt;/span&amp;gt;
                        &amp;lt;span&amp;gt;{lng.name}&amp;lt;/span&amp;gt;
                      &amp;lt;/button&amp;gt;
                    &amp;lt;/Menu.Item&amp;gt;
                  );
                })}
              &amp;lt;/div&amp;gt;
            &amp;lt;/Menu.Items&amp;gt;
          &amp;lt;/Transition&amp;gt;
        &amp;lt;/Menu&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/&amp;gt;
  );
};

export default LanguageSelector;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the component above, a dropdown shows language and country flag options. When selected, the language is applied across the application. We use the function i18n.changeLanguage(languageCode) to change the application language.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7iju6s8k0xdfcmevn10y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7iju6s8k0xdfcmevn10y.png" alt=" " width="485" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here in our SampleForm Component , we are rendering our localization based labels,t function is used and the key of the word or the statement u need is provided ad the parameter to render that label in the current language selected&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import ModuleContainer from "components/shared/moduleContainer/ModuleContainer";
import { useTranslation } from "react-i18next";

function SampleForm() {
  const { t } = useTranslation();
  return (
    &amp;lt;&amp;gt;
      &amp;lt;ModuleContainer title={"Sample Form"} hideBackButton={true}&amp;gt;
        &amp;lt;p&amp;gt;{t("hello")}&amp;lt;/p&amp;gt;
        &amp;lt;p&amp;gt;{t("cancel")}&amp;lt;/p&amp;gt;
      &amp;lt;/ModuleContainer&amp;gt;
    &amp;lt;/&amp;gt;
  );
}

export default SampleForm;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhn0s5ly2k60ryourqp5y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhn0s5ly2k60ryourqp5y.png" alt=" " width="675" height="675"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmtceud7mq00ur4txc36l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmtceud7mq00ur4txc36l.png" alt=" " width="675" height="675"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here , based on language selected the translation is rendered , in this way across the application labels and messages can be transformed to be rendered in any desired language across your react application .&lt;/p&gt;




&lt;p&gt;If you'd like to be in the know, subscribe, clap, like and share. Cheers!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>programming</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
