Mahamudul Hasan Rubel
HomeBlogCoursesAboutProjectsSkillsExperiencePhotosContact
Mahamudul Hasan Rubel

Senior Software Engineer crafting high-performance web applications and SaaS platforms.

Navigation

  • Home
  • Blog
  • Courses
  • About
  • Projects
  • Skills
  • Experience
  • Photos
  • Contact

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
Lesson 47 of the Intermediate React: Hooks, State & Data Patterns course
ReactJune 26, 20263 min read

Internationalization Basics: Implementing i18n in React Dashboards

Learn to implement i18n in your React dashboard. We cover managing language state and using context to provide localized UI strings to your components.

Reacti18nlocalizationcontextUIarchitecturejavascriptfrontend

Previously in this course, we explored Managing Global Modals: A Scalable Pattern for React UI to decouple UI overlays from component logic. In this lesson, we apply similar architectural principles to solve a different challenge: globalizing your application through i18n (internationalization).

Making an application truly global isn't just about translating text; it's about building a system that can handle different languages, date formats, and layout directions. For our dashboard, we will implement a robust provider-based architecture that allows users to toggle their preferred language dynamically.

Understanding i18n Architecture from First Principles

At its core, i18n is the process of preparing your software to be adapted to various languages and regions without engineering changes. The companion process, localization (often abbreviated as l10n), is the actual translation and formatting.

To implement this in React, we need three distinct layers:

  1. The Translation Dictionary: A JSON object or external service containing key-value pairs for each supported locale.
  2. The Language State: A mechanism to track the user's current selection (e.g., 'en', 'es', 'fr').
  3. The Context Provider: A wrapper that broadcasts the current language and a helper function to retrieve the correct string based on that language.

We avoid hardcoding strings directly in our components. Instead, we reference keys, ensuring our UI remains clean and maintainable.

Building a Translation Context

We’ll start by creating a dedicated provider. This keeps our language state centralized, similar to how we managed state in Advanced Context Patterns: Scalable State for React Dashboards.

JAVASCRIPT
// src/context/I18nContext.jsx
import React, { createContext, useContext, useState } from CE9178">'react';

const translations = {
  en: { welcome: "Welcome to your Dashboard" },
  es: { welcome: "Bienvenido a su Panel" }
};

const I18nContext = createContext();

export const I18nProvider = ({ children }) => {
  const [locale, setLocale] = useState(CE9178">'en');

  const t = (key) => translations[locale][key] || key;

  return (
    <I18nContext.Provider value={{ locale, setLocale, t }}>
      {children}
    </I18nContext.Provider>
  );
};

export const useTranslation = () => useContext(I18nContext);

By exposing a t function, any component can now access localized text without knowing the internal structure of our dictionary.

Implementing Localization in the Dashboard

Now, integrate this into your dashboard. In your main layout or root component, wrap your application with the I18nProvider.

JAVASCRIPT
// Example usage in a dashboard header
const DashboardHeader = () => {
  const { t, setLocale } = useTranslation();

  return (
    <header>
      <h1>{t(CE9178">'welcome')}</h1>
      <select onChange={(e) => setLocale(e.target.value)}>
        <option value="en">English</option>
        <option value="es">Español</option>
      </select>
    </header>
  );
};

This approach allows your dashboard to react instantly to language changes. When setLocale is called, the context value updates, causing all components consuming useTranslation to re-render with the new language strings.

Hands-on Exercise

Your task is to extend the existing dashboard settings.

  1. Create a locales folder and move your translation dictionary into a separate JSON file.
  2. Add a third language (e.g., 'fr') to your dictionary.
  3. Update the I18nProvider to persist the chosen language to localStorage. You can reference the logic we built in Building a useLocalStorage Hook to ensure the user's preference survives a page refresh.

Common Pitfalls

  • Hardcoding Fallbacks: Always ensure your t function returns the key if the translation is missing. This makes it immediately obvious during development when a string hasn't been localized.
  • Context Re-renders: Because the I18nContext value changes every time the user switches languages, ensure your provider value is memoized if the dictionary grows large, or keep the dictionary outside the component tree to avoid unnecessary object recreation.
  • Directionality (RTL): Remember that some languages (Arabic, Hebrew) are written Right-to-Left. If you plan to support these, you'll need to toggle a CSS class on the <body> or root <div> to handle layout mirroring.

Recap

We have successfully decoupled our UI text from our components using a custom I18nProvider. By centralizing language state and providing a helper function, we've created a scalable foundation for a multi-language dashboard. This pattern of using context to distribute configuration—like language or theme—is a standard approach in professional React applications.

Up next: We will integrate real-time communication into our dashboard by learning to handle WebSocket connections for live updates.

Previous lessonOptimizing Asset LoadingNext lesson Managing WebSocket Connections
Back to Blog

Similar Posts

ReactJune 26, 20263 min read

Implementing Keyboard Shortcuts for Accessible React Dashboards

Enhance your React dashboard's accessibility and efficiency by implementing global keyboard shortcuts using useEffect, key mapping, and focus management.

Read more
ReactJune 26, 20264 min read

Managing Global Modals: A Scalable Pattern for React UI

Stop prop-drilling modal visibility. Learn to build a global modal system using Context API and state to trigger UI overlays from anywhere in your app.

Part of the course

Intermediate React: Hooks, State & Data Patterns

intermediate · Lesson 47 of 48

  1. 1

    Mastering useRef for DOM Access

    4 min
  2. 2

    Persistent Mutable Values with useRef

    4 min
  3. 3

    Memoizing Expensive Calculations with useMemo

    3 min
Read more
ReactJune 26, 20263 min read

Handling Large Datasets in UI: Performance, Tables, and UX

Learn how to manage large datasets in React using pagination, infinite scrolling, and virtualization to maintain high performance and a smooth user experience.

Read more
4

Optimizing Function References with useCallback

3 min
  • 5

    Introduction to Custom Hooks

    4 min
  • 6

    Building a useLocalStorage Hook

    4 min
  • 7

    Refactoring Dashboard Settings

    4 min
  • 8

    Complex State with useReducer

    3 min
  • 9

    Managing Object-Based State

    3 min
  • 10

    Introduction to Context API

    3 min
  • 11

    Architecting Global State with Context and Reducer

    3 min
  • 12

    Implementing Theme Context

    4 min
  • 13

    Structuring State for Performance

    3 min
  • 14

    Handling Authentication State

    3 min
  • 15

    Integrating Reducers with Auth State

    3 min
  • 16

    Introduction to React Router

    3 min
  • 17

    Dynamic Routing with URL Parameters

    3 min
  • 18

    Nested Routes and Layouts

    4 min
  • 19

    Protected Routes for Authenticated Views

    3 min
  • 20

    Programmatic Navigation

    3 min
  • 21

    Building the Dashboard Navigation Structure

    3 min
  • 22

    Asynchronous Data Lifecycle

    3 min
  • 23

    Caching Strategies with React Query

    4 min
  • 24

    Mutations and Data Updates

    4 min
  • 25

    Synchronizing Client and Server State

    3 min
  • 26

    Integrating Live Data into the Dashboard

    3 min
  • 27

    Error Handling and Loading UI

    3 min
  • 28

    Controlled vs Uncontrolled Components

    3 min
  • 29

    Real-time Form Validation

    3 min
  • 30

    Schema-based Validation with Zod

    3 min
  • 31

    Handling Multi-step Forms

    3 min
  • 32

    Optimizing Form Submissions

    3 min
  • 33

    Performance Profiling with React DevTools

    3 min
  • 34

    Refactoring for Scalability

    3 min
  • 35

    Finalizing Dashboard Data Flow

    3 min
  • 36

    Deploying the Application

    4 min
  • 37

    Advanced Hook Composition

    3 min
  • 38

    Implementing Middleware for State

    3 min
  • 39

    Advanced Context Patterns

    3 min
  • 40

    Router Loaders and Data Prefetching

    3 min
  • 41

    Complex Route Guards

    3 min
  • 42

    Handling Large Datasets in UI

    3 min
  • 43

    Testing Hooks and Components

    3 min
  • 44

    Managing Global Modals

    4 min
  • 45

    Implementing Keyboard Shortcuts

    3 min
  • 46

    Optimizing Asset Loading

    4 min
  • 47

    Internationalization Basics

    3 min
  • 48

    Managing WebSocket Connections

    3 min
  • View full course