Internationalization (i18n) & Localization
Table of Contents
Overview
Comprehensive guide to implementing internationalization and localization in applications. Covers message translation, pluralization, date/time/number formatting, RTL languages, and integration with popular i18n libraries.
When to Use
- Building multi-language applications
- Supporting international users
- Implementing language switching
- Formatting dates, times, and numbers for different locales
- Supporting RTL (right-to-left) languages
- Extracting and managing translation strings
- Implementing pluralization rules
- Setting up translation workflows
Quick Start
Minimal working example:
// i18n.ts
import i18next from "i18next";
import Backend from "i18next-http-backend";
import LanguageDetector from "i18next-browser-languagedetector";
await i18next
.use(Backend)
.use(LanguageDetector)
.init({
fallbackLng: "en",
debug: process.env.NODE_ENV === "development",
interpolation: {
escapeValue: false, // React already escapes
},
backend: {
loadPath: "/locales/{{lng}}/{{ns}}.json",
},
detection: {
order: ["querystring", "cookie", "localStorage", "navigator"],
caches: ["localStorage", "cookie"],
},
});
// ... (see reference guides for full implementation)
Reference Guides
Detailed implementations in the references/ directory:
| Guide |
Contents |
| i18next (JavaScript/TypeScript) |
i18next (JavaScript/TypeScript) |
| React-Intl (Format.js) |
React-Intl (Format.js) |
| Python i18n (gettext) |
Python i18n (gettext) |
| Date and Time Formatting |
Date and Time Formatting |
| Number and Currency Formatting |
Number and Currency Formatting |
| Pluralization Rules |
Pluralization Rules |
| RTL (Right-to-Left) Language Support |
RTL (Right-to-Left) Language Support |
| Translation Management |
Translation Management |
| Locale Detection |
Locale Detection |
| Server-Side i18n |
Server-Side i18n |
Best Practices
✅ DO
- Extract all user-facing strings to translation files
- Use ICU message format for complex messages
- Support pluralization correctly for each language
- Use locale-aware date/time/number formatting
- Implement RTL support for Arabic, Hebrew, etc.
- Provide fallback language (usually English)
- Use namespaces to organize translations
- Test with pseudo-localization (ääçćëńţś)
- Store locale preference (cookie, localStorage)
- Use professional translators for production
- Implement translation management workflow
- Support dynamic locale switching
- Use translation memory tools
❌ DON'T
- Hardcode user-facing strings in code
- Concatenate translated strings
- Assume English grammar rules apply to all languages
- Use generic plural forms (one/many) for all languages
- Forget about text expansion (German is ~30% longer)
- Store dates/times in locale-specific formats
- Use flags to represent languages (flag ≠ language)
- Translate technical terms without context
- Mix translation keys with UI strings
- Forget to translate alt text, titles, placeholders
- Assume left-to-right layout
1---2name: internationalization-i18n3description: Implement internationalization (i18n) and localization including message extraction, translation catalogs, pluralization rules, date/time/number formatting, RTL language support, and i18n libraries like i18next and gettext. Use for multi-language, translation, or localization needs.4---5
6# Internationalization (i18n) & Localization
7
8## Table of Contents
9
10- [Overview](#overview)
11- [When to Use](#when-to-use)
12- [Quick Start](#quick-start)
13- [Reference Guides](#reference-guides)
14- [Best Practices](#best-practices)
15
16## Overview
17
18Comprehensive guide to implementing internationalization and localization in applications. Covers message translation, pluralization, date/time/number formatting, RTL languages, and integration with popular i18n libraries.
19
20## When to Use
21
22- Building multi-language applications
23- Supporting international users
24- Implementing language switching
25- Formatting dates, times, and numbers for different locales
26- Supporting RTL (right-to-left) languages
27- Extracting and managing translation strings
28- Implementing pluralization rules
29- Setting up translation workflows
30
31## Quick Start
32
33Minimal working example:
34
35```typescript
36// i18n.ts
37import i18next from "i18next";
38import Backend from "i18next-http-backend";
39import LanguageDetector from "i18next-browser-languagedetector";
40
41await i18next
42 .use(Backend)
43 .use(LanguageDetector)
44 .init({
45 fallbackLng: "en",
46 debug: process.env.NODE_ENV === "development",
47
48 interpolation: {
49 escapeValue: false, // React already escapes
50 },
51
52 backend: {
53 loadPath: "/locales/{{lng}}/{{ns}}.json",
54 },
55
56 detection: {
57 order: ["querystring", "cookie", "localStorage", "navigator"],
58 caches: ["localStorage", "cookie"],
59 },
60 });
61// ... (see reference guides for full implementation)
62```
63
64## Reference Guides
65
66Detailed implementations in the `references/` directory:
67
68| Guide | Contents |
69|---|---|
70| [i18next (JavaScript/TypeScript)](references/i18next-javascripttypescript.md) | i18next (JavaScript/TypeScript) |
71| [React-Intl (Format.js)](references/react-intl-formatjs.md) | React-Intl (Format.js) |
72| [Python i18n (gettext)](references/python-i18n-gettext.md) | Python i18n (gettext) |
73| [Date and Time Formatting](references/date-and-time-formatting.md) | Date and Time Formatting |
74| [Number and Currency Formatting](references/number-and-currency-formatting.md) | Number and Currency Formatting |
75| [Pluralization Rules](references/pluralization-rules.md) | Pluralization Rules |
76| [RTL (Right-to-Left) Language Support](references/rtl-right-to-left-language-support.md) | RTL (Right-to-Left) Language Support |
77| [Translation Management](references/translation-management.md) | Translation Management |
78| [Locale Detection](references/locale-detection.md) | Locale Detection |
79| [Server-Side i18n](references/server-side-i18n.md) | Server-Side i18n |
80
81## Best Practices
82
83### ✅ DO
84
85- Extract all user-facing strings to translation files
86- Use ICU message format for complex messages
87- Support pluralization correctly for each language
88- Use locale-aware date/time/number formatting
89- Implement RTL support for Arabic, Hebrew, etc.
90- Provide fallback language (usually English)
91- Use namespaces to organize translations
92- Test with pseudo-localization (ääçćëńţś)
93- Store locale preference (cookie, localStorage)
94- Use professional translators for production
95- Implement translation management workflow
96- Support dynamic locale switching
97- Use translation memory tools
98
99### ❌ DON'T
100
101- Hardcode user-facing strings in code
102- Concatenate translated strings
103- Assume English grammar rules apply to all languages
104- Use generic plural forms (one/many) for all languages
105- Forget about text expansion (German is ~30% longer)
106- Store dates/times in locale-specific formats
107- Use flags to represent languages (flag ≠ language)
108- Translate technical terms without context
109- Mix translation keys with UI strings
110- Forget to translate alt text, titles, placeholders
111- Assume left-to-right layout