How to handle internationalization with Hooks in React ? Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Handling internationalization (i18n) involves using the state to manage the current language and updating the UI based on the selected language. This typically includes creating language files or dictionaries for each supported language and dynamically rendering the content based on the selected language in your components. Step to Handling Internationalization with Hooks:Choose an i18n Library: Select an internationalization library for React. Popular choices include react-i18next and react-intl. Install the chosen library using npm or yarn.npm install i18next react-i18nextInitialize the i18n Library: Initialize the i18n library in your application, typically in a top-level component or in your main entry file. Configure it with the supported languages and any necessary settings. Create a Custom Hook for Language Switching: Write a custom hook, let's call it useLanguage, to handle language switching. This hook can include functions to change the current language.Use the Custom Hook in Components: Import and use the useLanguage hook in components where you want to manage language switching.Handle Translation in Components: Use the useTranslation hook from the i18n library to translate text within your components.Example: Below is an example of handling internationalization with Hooks. JavaScript // App.js import React from 'react'; import LanguageSwitcher from './components/LanguageSwticher'; import ExampleComponent from './components/Greeting'; import "../src/components/i18n" const App = () => { return ( <div> <LanguageSwitcher /> <ExampleComponent /> </div> ); }; export default App; JavaScript // i18n.js import i18n from 'i18next'; import { initReactI18next } from 'react-i18next'; i18n .use(initReactI18next) .init({ resources: { en: { translation: { greeting: 'Hello!', }, }, fr: { translation: { greeting: 'Bonjour!', }, }, }, lng: 'en', fallbackLng: 'en', interpolation: { escapeValue: false, }, }); export default i18n; JavaScript // useLanguage.js import { useState } from 'react'; import i18n from './i18n'; const useLanguage = () => { const [currentLanguage, setCurrentLanguage] = useState(i18n.language); const changeLanguage = (language) => { i18n.changeLanguage(language); setCurrentLanguage(language); }; return { currentLanguage, changeLanguage }; }; export default useLanguage; JavaScript // LanguageSwitcher.js import React from 'react'; import useLanguage from './useLanguage'; const LanguageSwitcher = () => { const { currentLanguage, changeLanguage } = useLanguage(); return ( <div> <p>Current Language: {currentLanguage}</p> <button onClick={() => changeLanguage('en')}> Switch to English </button> <button onClick={() => changeLanguage('fr')}> Switch to French </button> </div> ); }; export default LanguageSwitcher; CSS /* LanguageSwitcher.css */ .language-switcher-container { display: flex; flex-direction: column; align-items: center; padding: 20px; border: 1px solid #ccc; border-radius: 8px; margin-bottom: 20px; } button { margin-top: 10px; padding: 8px 16px; font-size: 14px; cursor: pointer; } button:hover { background-color: #f0f0f0; } Step to run the App: npm startOutput: Output Comment More infoAdvertise with us Next Article How to handle internationalization with Hooks in React ? F faheemakt6ei Follow Improve Article Tags : Web Technologies ReactJS MERN-QnA WebTech-FAQs Similar Reads How does internationalization work in JavaScript? Understanding Internationalization (i18n) and Localization (L10n)Internationalization (often abbreviated as i18n) is the process of designing products and services to easily adapt to various languages and cultures. In contrast, localization (or L10n) involves tailoring internationalized software for 3 min read How to handle input forms with useState Hook in React ? Handling input forms with useState in React involves creating state variables to store the values of input fields and updating them as the user interacts with the form. Handling input forms with useState:State Variables: Define state variables to hold the values of input fields. Each input field typ 2 min read Implementing Internationalization in React Components Internationalization (i18n) makes your app friendly to people who speak different languages. It's like having a multilingual superpower for your application. With internationalization in React, you can easily tweak your app so that it speaks the language of your users, no matter where they come from 4 min read How to Implement Internationalization (i18n) in Redux Applications? Implementing internationalization (i18n) in a Redux application enhances its accessibility and usability by allowing users to interact with the application in their preferred language. With i18n, your Redux app becomes multilingual, accommodating users from diverse linguistic backgrounds and improvi 6 min read React.js Blueprint Typography Lists Internationalization Blueprint is a React-based UI toolkit for the web. This library is very optimized and popular for building interfaces that are complex and data-dense for desktop applications. In this article, we'll discuss React.js Blueprint Typography Lists Internationalization. Typography is used to add text in v 3 min read Like