Pattern: Multi-language apps and sites
Note for AI agents: This page is baseline guidance, not an exact prescription. Read it, tell your owner what applies to their project, and get their approval before you change anything. Your project's own rules take precedence. If something important for this project is missing here, suggest it to your owner.
For agents
- Offer as a suggestion. This page is the design recipe; the audit checklist for the topic is on the i18n topic page.
- Core ideas: store strings per language in rows or per-language files (never as one column per language in the database), use standard codes and message formats, translate only the app’s fixed text, and fail the build on missing strings.
- Related: notifications.
1. Problem
Hard-coded text, string concatenation, English-only plurals and fixed date formats make later languages expensive. Right-to-left languages break layouts built with left and right assumptions.
2. Options
| Topic | Option | Upside | Downside |
|---|---|---|---|
| Storage | Translation rows (key, language, text) (recommended) | Add a language without changing the schema | Joins or lookups |
| Storage | One column per language | Simple at first | Schema change per language; many empty cells |
| Plurals | Message format with plural rules (ICU) | Correct for languages with several plural forms | Learning curve |
| Plurals | if count == 1 in code |
Quick | Wrong for many languages |
| Dates/numbers | Locale data (CLDR) | Correct local formats | Needs a library |
3. Recommended design
- Language codes: use BCP 47 tags (RFC 5646; W3C’s language tag guidance explains how to choose them).
- Message format: use ICU MessageFormat for plurals and gender, so each language defines its own forms. Never build sentences by joining pieces.
- Dates, numbers, currencies: use CLDR-based locale data from your platform or library.
- Right-to-left: use logical properties and direction-aware layouts; W3C’s guidance covers the
dirattribute and markup for right-to-left text. - Resource files: platform tools (Android’s localisation resources, web i18n files) with one source of truth; the app picks the language by device setting plus the user’s choice.
- What is translated: only the app’s fixed text. User-written content is not machine-translated by default.
- Fallback chain: requested language → base language (for example
pt-BR→pt) → default language. Document it. - Missing translation check in the build: the build lists keys missing in any language and fails (or warns, by project choice). This site does exactly that for its own i18n files.
- Time zones: “day” means the user’s time zone, not the server’s (practitioner experience).
- Names and layouts: allow text expansion (some languages need more space); do not hard-code widths.
4. Scenarios and edge cases
- Plural “1 comment / 2 comments” in Arabic, Polish, Russian: ICU plural rules handle several forms.
- Language list changes: the translation rows model needs only new rows and a menu entry.
- User content in another language than the interface: shown as written.
- Missing key in production: shows the fallback language text, and monitoring records the miss.
5. Common mistakes
- Concatenating strings.
- A column per language in the database.
- English-only plural logic.
- Fixed date formats.
- Left/right instead of start/end in layouts.
- No check for missing strings.
6. How to audit
- What: no hard-coded visible text.
- How to check: search the code for string literals in UI components; switch to a pseudo-language.
- Evidence: list of findings or an all-translated screenshot.
- What: plurals use message format.
- How to check: read a plural string in two languages.
- Evidence: the message source.
- What: missing strings are caught.
- How to check: delete a key in one language and build.
- Evidence: warning or failure output.
- What: right-to-left works.
- How to check: run the app in a right-to-left language.
- Evidence: screenshots.
Sources
- RFC 5646: Tags for Identifying Languages — IETF
- ICU: Formatting Messages — Unicode ICU
- Unicode CLDR Project — Unicode
- Localize your app — Android Developers
- Structural markup and right-to-left text in HTML — W3C Internationalization
- Localization vs. Internationalization — W3C Internationalization
- Language tags in HTML and XML — W3C Internationalization