Kayavak / Recaps / Internationalisation
Recaps · Volume 23
Internationalisation
The revision sheet of every chapter, on one page: the key ideas, the numbers worth knowing, the pitfalls and the words. Use it before an interview, after a chapter, or to find which chapter to reread. Each title opens its chapter; below each sheet are its exercises, companion and TiffinBox stage, and the misconceptions the companion corrects.
01
Key ideas
- Four layers: bytes, code units, code points, grapheme clusters. Every text bug confuses two of them.
- Unicode assigns code points U+0000–U+10FFFF; encodings (UTF-8, UTF-16, UTF-32) turn them into bytes.
- UTF-8: 1 byte for ASCII, 2 for most alphabetic scripts, 3 for Indic and CJK, 4 for emoji; ASCII-compatible and self-synchronising.
- UTF-16: one unit in the BMP, a surrogate pair above it; JavaScript, Java and Kotlin count units.
- Graphemes: combining marks, conjuncts, emoji modifiers, ZWJ sequences, flags. Swift counts these; others need a segmenter.
- Normalise (NFC for storage and comparison, NFKC for identifiers) at the boundary.
- Mojibake comes from undeclared or wrong encodings at boundaries; declare UTF-8 everywhere.
- Name the unit of every limit; truncate at grapheme boundaries.
Numbers to remember
- 1,114,112 code points; ~155,000 assigned.
- Telugu curd rice: 34 bytes, 12 code points, 6 graphemes; family emoji: 18 bytes, 8 UTF-16 units, 5 code points, 1 grapheme.
Glossary
- Code point: Unicode's number for a character, U+XXXX.
- Code unit: the fixed-size piece of an encoding (8, 16 or 32 bits).
- Surrogate pair: two UTF-16 units encoding one code point above U+FFFF.
- Grapheme cluster: what a user perceives as one character.
- Virama: an Indic sign that suppresses a consonant's vowel and joins it to the next consonant.
- ZWJ: zero-width joiner, U+200D, which combines emoji into one.
- NFC / NFD / NFKC / NFKD: Unicode normalisation forms.
- Mojibake: text garbled by decoding with the wrong encoding.
- BOM: byte order mark, U+FEFF at the start of a file.
02
Key ideas
- Code-point order is for machines; people need locale-aware collation.
- The UCA compares base letters, then accents, then case; CLDR tailors it per language (Swedish ä after z, Turkish ı, Spanish ñ).
- Options: numeric (
kn), strength (ks), punctuation handling, named variants.
- Case mapping is for display and is language-dependent; case folding (plus normalisation) is for comparison.
- Use the platform collator with the viewer's locale; reuse collators and sort keys.
- PostgreSQL: libc vs ICU providers; indexes follow a collation; nondeterministic collations for caseless equality; rebuild indexes after collation-library upgrades.
- MySQL: use
utf8mb4.
- Search: normalise, fold, tokenise per language, stem, expand with synonyms and transliterations; hybrid with multilingual embeddings.
Numbers to remember
- glibc 2.28 (2018) changed sort order and silently invalidated text indexes.
- Collation levels: primary (letters), secondary (accents), tertiary (case).
Glossary
- Collation: rules for ordering and comparing strings.
- UCA / DUCET: Unicode Collation Algorithm and its default table.
- Tailoring: a language's changes to the default collation.
- Strength: which levels a comparison considers.
- Case folding: mapping for caseless comparison.
- Nondeterministic collation: one where different strings can compare equal.
- Transliteration: writing a word in another script (पनीर → paneer).
- Analyser: a search engine's pipeline of tokeniser and filters.
03
Key ideas
- Instants (a point on the timeline) vs civil times (what clocks say somewhere); converting needs a zone's rules.
- Offset ≠ zone. Use IANA names (
Asia/Kolkata), never abbreviations (IST).
- The tz database changes several times a year; keep it current everywhere.
- DST gaps (times that don't exist) and overlaps (times that occur twice); choose the resolution.
- Store: past events as UTC instants; future local events as local time + zone; recurring schedules as local time + zone + rule; dates as dates.
- Durations (24 hours) vs periods (1 day); use periods in the user's zone for "same time tomorrow".
- Daily reports need a named reporting zone.
- ISO 8601 with offsets on the wire; monotonic clocks for intervals; inject the clock in tests.
- PostgreSQL:
timestamptz for instants; display and day arithmetic follow the session zone.
Numbers to remember
- India +05:30 (no DST), Nepal +05:45, UAE +04:00, New York −05:00/−04:00.
- 2026 US DST: starts 8 March, ends 1 November.
- 2038: 32-bit Unix time overflow.
Glossary
- UTC: the reference timeline, no DST.
- Offset: local time minus UTC at a moment.
- Time zone: a region's rules over time, named in the IANA database.
- DST gap / overlap: skipped / repeated local times.
- Fold: Python's flag picking the first or second of a repeated local time.
- Duration / period: exact elapsed time / calendar amount.
- Monotonic clock: a clock that never goes backwards.
- RRULE: iCalendar recurrence rule.
- Leap-second smearing: spreading a leap second over hours.
04
Key ideas
- BCP 47 tags: language-script-region plus
-u- extensions (numbering system, calendar, hour cycle, collation).
- Negotiate locales with distance-aware matching; fall back per message; keep language and region choices separate; don't infer language from IP.
- CLDR (via ICU) provides number, date, currency, plural, list, relative-time and name data; output changes between versions.
- Format with platform APIs; parse input with the user's locale and show it back; exchange data in locale-neutral formats.
- Plural categories: zero, one, two, few, many, other; ordinals have their own rules.
- Currency belongs to the amount; formatting belongs to the viewer; minor units vary (0, 2, 3).
- Money: integer minor units or decimals, never floats; stated rounding modes and points; allocate remainders; store FX rate and time with conversions.
Numbers to remember
- Indian grouping 1,23,45,678; 1 lakh = 100,000; 1 crore = 10,000,000.
- Minor units: JPY 0, INR 2, KWD 3.
- Lab: 1 million float additions of 0.10 drifted by 0.0000013; GST per line ₹22.20 vs total ₹22.23.
Glossary
- BCP 47: the standard for language tags.
- CLDR / ICU: locale data and the library implementing it.
- Plural category: a CLDR class of numbers needing one word form.
- ISO 4217: currency codes and minor units.
- Minor unit: the smallest currency unit (paisa, cent, fils).
- Half-even rounding: ties round to the even digit.
- Allocation: splitting an amount without losing remainders.
05
Key ideas
- Externalise every user-visible string, including server errors, emails, notifications and accessibility labels; use stable keys.
- Whole sentences with named placeholders; never concatenate; format numbers and dates inside messages with the locale.
- ICU MessageFormat:
plural, selectordinal, select; translators add the categories their language needs; MessageFormat 2 and Fluent are newer options.
- Give translators context: descriptions, placeholder examples, limits, screenshots, glossary, style guide.
- Layouts must grow and wrap; expect 30–300% expansion; leave vertical room for scripts with marks.
- Pseudo-localise in CI (accents, expansion, brackets, RTL).
- Pipeline: extraction → TMS (translation memory, glossary) → human or machine translation with review → automated checks → in-context review → merge; per-string fallback; over-the-air text updates on mobile.
- Per-app language choice; language-specific URLs with
hreflang; lang attributes.
Numbers to remember
- Lab expansion of a 21-character label: German 170%, Tamil 160%, Telugu 193%.
- Short strings (≤10 characters) can grow 100–300%.
Glossary
- Resource file: a file of keyed, translatable strings.
- ICU MessageFormat: message syntax with placeholders, plurals and selection.
- TMS: translation management system.
- Translation memory: stored past translations for reuse.
- Post-editing: human correction of machine translation.
- Pseudo-localisation: an automatic fake translation used for testing.
- String freeze: a cut-off for text changes before a release.
- hreflang: HTML/HTTP annotation linking language versions of a page.
06
Key ideas
- RTL scripts: Arabic (and Urdu, Persian), Hebrew and others; RTL support = mirrored layout + correct mixed-direction text.
- Text is stored in logical order; the Unicode Bidirectional Algorithm computes visual order from bidi classes (strong, weak, neutral, explicit).
- Isolate inserted values: FSI/LRI/RLI … PDI,
<bdi>, dir="auto", BidiFormatter. Prefer isolates to embeddings and overrides.
- Use logical layout properties (start/end, inline-start/end, leading/trailing); set document direction from the locale.
- Flip navigation and progress icons; don't flip media controls, logos, numbers, phone numbers, URLs or code.
- Arabic locales differ in digits; accept both in input.
- Strip or reject bidi controls in names and file names; flag them in code review (Trojan Source).
- Test with pseudo-RTL, real mixed data and native reviewers.
Numbers to remember
- U+202E RLO; U+2066–U+2069 LRI, RLI, FSI, PDI; U+200E/U+200F LRM/RLM.
- CVE-2021-42574: Trojan Source.
Glossary
- Logical order: storage and reading order.
- Visual order: left-to-right position on screen.
- Bidi class: a code point's directional type.
- Embedding level: the depth of direction nesting; odd levels are RTL.
- Isolate: a bidi construct that keeps inserted text from affecting its surroundings.
- Mirroring: flipping layout or paired glyphs for RTL.
- Logical properties: start/end layout properties.
07
Key ideas
- Names: one full-name field, any script, plus "what should we call you"; no ASCII validation; strip control characters.
- Addresses: per-country forms from data, landmarks and map pins, store as entered plus normalised, ISO country codes.
- Phones: parse with libphonenumber using a default region; store E.164; check type; verify with OTP.
- Domains: IDNA/Punycode; defend against homographs with mixed-script and confusable checks; accept Unicode email addresses.
- Identifiers: NFKC + case folding (or PRECIS), confusable skeletons, no invisible or bidi characters.
- Storage: UTF-8/utf8mb4; know whether limits count bytes or characters; size for Indic text; BOM for Excel CSV; embed fonts in PDFs.
- Wire: charset in Content-Type; Accept-Language with Vary; percent-encoded UTF-8 URLs; ISO codes in APIs; error codes not messages.
- SMS: 160 GSM-7 vs 70 UCS-2 characters; push payloads 4 KB in bytes; localise on device with keys.
- Market rules (tax, payments, invoices, privacy, residency) as per-market configuration.
Numbers to remember
- E.164: at most 15 digits. Indian PIN code: 6 digits.
- SMS: 160/153 (GSM-7), 70/67 (UCS-2).
- APNs/FCM payload: 4,096 bytes.
- MySQL InnoDB index key: 3,072 bytes = 768 utf8mb4 characters.
Glossary
- E.164: international phone-number format.
- IDNA / Punycode: conversion of Unicode domain labels to ASCII
xn-- form.
- Homograph attack: impersonation with look-alike characters.
- Confusable skeleton: UTS #39 form mapping look-alikes together.
- EAI / SMTPUTF8: internationalised email addresses.
- GSM-7 / UCS-2: SMS encodings.
- DLT: India's registration system for commercial SMS templates and senders.