← Back to Chapters

Internationalization Basics

? Internationalization Basics

? Quick Overview

Internationalization (i18n) is the process of preparing a React application to support multiple languages and regions using tools like react-i18next.

? Key Concepts

  • Language resources
  • Translation keys
  • Dynamic language switching
  • Locale-based formatting

⚛️ Introduction

Internationalization ensures your app works globally with consistent UX and accessibility.

? Installation

? View Code Example
# Install i18n dependencies
npm install i18next react-i18next

? Basic Setup

? View Code Example
// i18n configuration file
import i18n from "i18next";
import { initReactI18next } from "react-i18next";

i18n.use(initReactI18next).init({
resources:{
en:{translation:{welcome:"Welcome to React",message:"This app supports multiple languages."}},
hi:{translation:{welcome:"React में आपका स्वागत है",message:"यह ऐप कई भाषाओं का समर्थन करता है।"}}
},
lng:"en",
fallbackLng:"en",
interpolation:{escapeValue:false}
});

export default i18n;

⚙️ Using Translations in Components

? View Code Example
// React component with language switch
const { t, i18n } = useTranslation();
i18n.changeLanguage("hi");

? Live Interactive Demo

Switch the language below to see how content updates dynamically without reloading the page.

Welcome to React

This app supports multiple languages.

Current Locale: en-US
Date Format: Loading...

? Folder Structure Example

? View Code Example
// Recommended folder layout
src/
├── i18n.js
├── App.js
└── locales/

? Example translation.json

? View Code Example
// English translations
{
"welcome":"Welcome to React",
"message":"This app supports multiple languages."
}

⚖️ Use Cases

  • Global SaaS platforms
  • Multi-region applications
  • Accessible public services

? Tips & Best Practices

  • Use consistent translation keys
  • Store translations externally
  • Use Suspense for lazy loading

? Try It Yourself

  1. Add a new language
  2. Switch languages dynamically
  3. Move translations to JSON