i18n, l10n and locale: separate responsibilities
Internationalization (i18n) prepares code and interfaces for multiple languages. Localization (l10n) adapts content, formats, imagery and experience to an audience. A locale such as pl-PL describes language and regional preferences, not a complete business profile. BCP 47 can also express script, as in zh-Hant. [1][2]
A Polish-speaking customer may live in Germany, buy in EUR and use Europe/Berlin. Do not infer currency, taxes, shipping country, permissions or time zone from locale alone. Model market, currency and time zone separately. The backend remains authoritative for prices and sales rules.
Language selection and fallback
locale.ts
export const SUPPORTED_LOCALES = ["en", "pl", "de", "pt-BR"] as const;
export type Locale = (typeof SUPPORTED_LOCALES)[number];
const DEFAULT_LOCALE: Locale = "en";
const supported = new Set<string>(SUPPORTED_LOCALES);
function isSupported(value: string): value is Locale {
return supported.has(value);
}
export function resolveLocale(preferences: readonly string[]): Locale {
for (const preference of preferences) {
let canonical: string | undefined;
try {
[canonical] = Intl.getCanonicalLocales(preference);
} catch (error) {
if (error instanceof RangeError) {
continue;
}
throw error;
}
if (canonical === undefined) {
continue;
}
const locale = new Intl.Locale(canonical);
if (isSupported(locale.baseName)) {
return locale.baseName;
}
if (isSupported(locale.language)) {
return locale.language;
}
}
return DEFAULT_LOCALE;
}
For public pages, an explicit language in the URL should take priority. On a neutral entry URL, consider a saved preference, ordered Accept-Language preferences and a default. Do not redirect a valid language URL based on browser settings. In an authenticated app, the profile language may take precedence over device defaults. [2][8][10]
The resolver below takes an already ordered preference list, canonicalizes identifiers and allows only four configured locales. It is deliberately limited: it does not parse HTTP headers, q weights or the full language-script-region hierarchy. pt-PT does not automatically become pt-BR. For larger products use a proven negotiation mechanism and define permitted equivalents. Separate locale fallback from individual message fallback; missing mandatory legal content must not be hidden by another market's translation. [2][5][10]
RFC 4647 distinguishes filtering (a set of matching tags) from lookup (one result, progressively truncating the range). ECMA-402 best fit may use additional linguistic knowledge and is implementation-dependent; it is not a business market-selection rule. For zh-Hant-HK, consider zh-Hant before any switch to zh-Hans. Define permitted mappings explicitly. Accept-Language can include q weights, a wildcard and q=0 exclusions. Use an HTTP parser, handle malformed input and define behavior when nothing matches; never pass the entire header to Intl.Locale. [10][22][1]
Intl, numbers, dates and grammar
formatting.ts
import type { Locale } from "./locale.js";
export function createOrderFormatters(locale: Locale, currency: string) {
const price = new Intl.NumberFormat(locale, {
style: "currency",
currency,
});
const quantity = new Intl.PluralRules(locale);
return { price, quantity };
}| Number | CLDR category | Example message |
|---|---|---|
| 1 | one | 1 kilogram |
| 2 | few | 2 kilogramy |
| 12 | many | 12 kilogramów |
| 22 | few | 22 kilogramy |
| 1.5 | other | 1,5 kilograma |
The Polish weight examples illustrate how grammatical categories affect noun inflection. ICU allows a separate =0 variant, such as “No products”, independently of the many category for zero. The other variant is the required default. [4][6]
Related article: JavaScript Date, Intl and Temporal.
Intl.NumberFormat displays an amount in the supplied currency; it does not convert exchange rates or perform exact financial arithmetic. Store money according to the domain contract, for example in minor units or a decimal type. Intl.DateTimeFormat accepts an explicit time zone, Intl.Collator supports sorting and Intl.Segmenter identifies text segments. Do not parse presentation strings. API support and locale data depend on the runtime. [1][3]
Pluralization is not a choice between one and everything else. Polish uses one, few, many and other (for example 1, 2, 12 and 1.5). A CLDR category is not a translated message. Use complete messages with variants and parameters instead of concatenating fragments. If the displayed value is rounded, align formatting and plural selection options. [1][4]
As of 30 November 2026, CLDR 49 (22 October 2026) is the current stable release. Node.js or browser data can be older. Test actual target runtimes; ECMA-402 conformance does not imply identical CLDR data. [1][34]
Intl.NumberFormat validates currency code structure but does not enforce a product currency allowlist. The example tests distinguish malformed EU from structurally valid XYZ.
Translation catalogs and message formats
Stable semantic keys such as checkout.payment.failed identify intent rather than spelling. Organize catalogs by domain or feature and provide translator context: parameter meaning, length constraints, UI location and screenshots. Do not share keys solely because two source strings are identical; grammar may differ in another language. Typed keys do not replace validation of message syntax and parameters. [5][6][7]
ICU MessageFormat supports complete messages with plural and select. Unicode MessageFormat 2 is a separate standard with different syntax; adopt it after checking parsers, extraction tools, translation platforms and target-language support. Do not assume existing ICU catalogs are compatible or that browsers provide a native MF2 runtime. [6][11][21]
Catalog formats and translation interchange
| Format | Role | Limitations |
|---|---|---|
| JSON | Application catalog, easy Git diffs | No common plural or metadata convention |
| PO | gettext catalog, context and plural forms | Requires compatible extraction and compilation |
| XLIFF | Interchange with a TMS | Verify markup and variants after import |
| ICU MessageFormat | Dynamic messages, plural and select | Parser and configuration dependencies |
| Unicode MF2 | Dynamic message standard | Different syntax; check runtime, editor and conversion |
Storage format and message syntax are different layers. JSON can contain ICU messages; XLIFF can transport them to translators. Test round trips for IDs, arguments, markup, context and translation status. XLIFF 2.1 is an OASIS Standard; 2.2 is a Committee Specification. Validate actual tool versions rather than inferring interoperability from the format number. [23][24][25]
Library and architecture selection
| Approach | Advantages | Limitations | When to choose |
|---|---|---|---|
| Build-time | Distribute ready-made variants | More artifacts; content updates need a release | Stable site, localized Angular builds |
| Runtime | Language switching and on-demand loading | Loading, errors and catalog compatibility | SaaS, modular applications |
| Hybrid | Critical text in SSR; smaller initial payload | Version and hydration coordination | Public portal with an extensive app |
| Tool | Strengths | Watch out for |
|---|---|---|
| Intl + catalogs | No additional engine; simple formatting | No sentence translation, extraction or loading |
| FormatJS / React Intl | ICU, extraction, rich text | Catalog compilation and parser compatibility |
| i18next | Namespaces, fallback, resource loading | Format and integration configuration; missing keys |
| Vue I18n | Vue integration, interpolation and pluralization | Syntax is not automatically ICU-compatible |
| Angular i18n | Extraction and localized builds | Runtime switching needs a separate approach |
| next-intl | Next.js integration, SSR, routing, ICU | Tied to Next.js architecture |
| Lingui | Extraction, catalogs and compiled ICU messages | Build and catalog workflow integration [26] |
| Transloco | Angular, runtime switching and lazy-loaded scopes | Check loaders, SSR and configuration [27] |
| Paraglide JS | Generated typed message functions and tree shaking | Depends on static references and bundler; some build options are experimental [28] |
A small app with a few fixed labels can use catalogs and Intl. In a product with dynamic messages, translators and multiple teams, an established library reduces the cost of maintaining a custom engine. FormatJS provides ICU and extraction, i18next provides namespaces and resource loading, and Vue I18n integrates with Vue. Angular supports localized builds; changing language without reloading requires an explicit mechanism. In Next.js, next-intl supports routing and SSR. [5][6][7][12][13][14]
Build-time localization provides known resources at deployment, at the cost of more artifacts. Runtime localization can fetch catalogs on demand but needs loading states, versioning and failure handling. A hybrid approach includes critical messages in the document and loads feature catalogs later. None guarantees correct translations or accessibility.
Application architecture: from two to 25 languages
| Product | Approach | Scaling condition |
|---|---|---|
| Small application | Intl and catalogs or a lightweight library | Single source of keys; whole messages |
| Public portal | SSR/SSG and distinct URLs | Map language counterparts |
| SaaS | Runtime or hybrid | Domain catalogs and atomic language switch |
| E-commerce | Independent language, market and currency | Backend owns price and availability |
| Enterprise / micro frontends | TMS, contracts and domain catalogs | Catalog owners and version compatibility |
| Multi-product monorepo | Shared i18n infrastructure | Independent catalog releases |
Frontend owns interface language, formatting and accessibility. Backend returns data and stable error codes with arguments, enforces market rules and localizes out-of-app messages such as emails. CMS owns content translations and publishing. A TMS (Translation Management System) coordinates translators; CI checks catalog contracts. Do not duplicate these responsibilities. In micro frontends, the host selects locale and domains own catalogs under a shared language-change contract; in a monorepo share infrastructure, not every message. [29]
SSR, hydration and performance
Related article: React Hydration Errors: Causes, Debugging and Fixes.
Resolve locale per server request and pass the same configuration and catalog version to the client. Never mutate a global language instance shared across concurrent requests. The client should not choose a new language from navigator.language before hydration. Even identical locale and time zone can produce different output with different ICU data; preserve initial server text where necessary.
When switching languages, load required catalogs before updating the interface. Commit only the latest request so a late response cannot overwrite a newer choice. Cache catalogs by locale, namespace and version; header-negotiated responses need appropriate Vary or equivalent cache-key separation. Public documents with explicit URLs are easier to cache than cookie-dependent variants. [10][14][15]
Separate first-view messages from feature catalogs such as billing and reports. Measure compressed payload, request count and time to a fully localized interface instead of assuming lazy loading is always faster. Immutable versioned resources can be cached for longer; the current release manifest needs a separate policy. Never put personalized responses in a shared cache. Commit a locale change only once required catalogs are ready. [10][15]
Multilingual SEO
Related article: robots.txt and sitemap.xml: technical SEO guide.
| URL structure | Advantages | Limitations |
|---|---|---|
| example.com/pl/ | Shared infrastructure; simpler maintenance | Consistent routing and page mapping |
| pl.example.com | Independent infrastructure if needed | DNS, certificates, sessions and monitoring |
| example.pl | Strong country signal, not language | Multiple domain costs; not a substitute for hreflang |
| example.com?lang=pl | Can represent a separate URL | Google advises against parameters as primary localization structure |
| Cookie without distinct URL | Preference in a private app | Public variants harder to index and share |
Use separate crawlable URLs such as /pl/cennik and /en/pricing. Map them using stable page IDs, not simple prefix substitution, because slugs may be translated. Add reciprocal hreflang annotations including self-references and optional x-default. Distinct indexable translations should be self-canonical; duplicate same-language regional variants require a separate canonical policy. [8][9]
Do not publish fake alternates, 404s or translations users cannot reach. Hreflang can be supplied through HTML, HTTP headers or sitemaps; choose one maintainable configuration source. Localize titles, descriptions, content and internal links, not just navigation. Google does not use lang or hreflang to detect the language of page content, but lang is important for accessibility. [8][9][16]
Subdirectories usually simplify a new portal; separate domains make sense when market organization requires them. Verify that hreflang targets are directly reachable, indexable, reciprocal and absolute URLs. Do not use x-default as a substitute for missing translations. Migrate URLs with a mapping and redirects to corresponding content. [8][9][30]
RTL, accessibility and security
Related article: Semantic HTML: Accessibility, SEO and Best Practices.
Set document lang and dir, and identify foreign-language passages with lang as required by WCAG. Direction depends on script; use CSS logical properties such as margin-inline-start instead of reversing each element manually. Isolate mixed-direction user content with bdi or dir=auto. Do not automatically mirror logos, digits or playback symbols. Test focus, longer labels, wrapping and narrow layouts. [16][17][18][20]
Treat catalogs as data, not trusted HTML. Interpolate through the safe rendering mechanism for the output context; in React use text nodes or controlled rich-text components. Do not disable escaping without understanding the rendering context or insert catalog content into innerHTML. Validate link destinations separately. Never include secrets in catalogs shipped to the client. [19]
TMS, versioning and AI translation quality
Workflow: extract messages, synchronize with the TMS, translate with context, review, validate and publish artifacts. Git holds the source contract and approved artifacts or their versions; define synchronization direction to avoid overwriting changes. Translation memory stores previous segment pairs, a glossary records approved terms and a style guide defines voice. A changed source message needs renewed review even if its key stays the same. [31][32]
AI and machine translation can draft content; do not automatically approve legal, payment or security messages. Do not send customer data to external models without appropriate authorization and processing safeguards. Protect placeholders and markup, validate syntax and terminology, and arrange review by someone familiar with the language and product. Track approved-message coverage and approval time, not just generated message count.
Quality workflow: extraction to deployment
| Test area | Case | Expected result |
|---|---|---|
| Unit | Polish: 1, 2, 12, 22, 1.5; invalid locale | Correct categories and controlled fallback |
| Contract | Missing argument, malformed ICU, changed type | CI rejects incompatible catalog |
| Integration | Rapid pl → de → en; concurrent SSR | Latest choice wins; no locale leakage |
| E2E / SEO | No cookie; direct URL, canonical and hreflang | Correct language, counterparts and HTTP statuses |
| Visual / accessibility | RTL, long labels, focus, narrow viewport | No clipping; correct lang/dir and keyboard support |
| Regression | Unavailable catalog, old client and new release | Controlled error message or compatible fallback |
In CI, check missing and unused keys, placeholder compatibility and message syntax with the library parser. Unit tests cover locale selection, fallback, pluralization and formatting; integration tests cover language switches, response ordering and SSR. E2E tests check switcher accessibility, document lang/dir, navigation and forms. Visual tests using pseudolocalization and RTL expose layout problems but cannot replace linguistic review.
Tie catalog deployments to application versions. Measure missing messages and load errors by locale and namespace without recording private placeholder values. Set quality gates for payment and legal screens; treat machine or AI translation as material for review, not automatic approval. Verify domain rules and customer support before launching a new market.
A parser validates message syntax, not linguistic correctness. Preserve the parameter and markup contract while allowing translators to reorder elements according to grammar. The matrix below is a product test plan, not results of library integration tests.
Migration and anti-patterns
| Anti-pattern | Consequence | Alternative |
|---|---|---|
| Concatenated sentence fragments | Broken grammar | Whole parameterized message |
| Global SSR locale | Languages leak between requests | Per-request context |
| All locales in initial bundle | Larger transfer | Split by language and domain |
| Fallback hides every missing key | Incomplete legal content | Block critical content publication |
| Country flag as language | Ambiguity | Language name and optional region |
| Automatic redirect on every URL | Lost choice and SEO problems | Negotiate only at neutral entry |
Stage 1: inventory text, formatting and market dependencies; define a locale contract and source language. Stage 2: migrate one complete feature, such as settings, and test a second language with different grammar. Stage 3: introduce domain catalogs, extraction and CI; add RTL or pseudolocalization before scaling language count. Stage 4: as coordination costs grow, introduce TMS, catalog owners and market-specific release gates. Migrate public URLs with their counterpart mapping. Do not build a custom engine up front or replace a proven library simply because a new standard exists. [33]
