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