跳转到内容
GitHub

Internationalization

Unaudited

此内容尚不支持你的语言。

Every user-facing string in the apps, the web client and the server’s errors is authored once in the repo-root locales/ directory and compiled into each platform’s native localization format. Translators never touch application code. The one exception is the CLI and TUI, which are English-only (The CLI Is English-Only).

Piece Role
locales/ Canonical ICU MessageFormat catalogs and config.json, the supported-locale set
xtask i18n Compiles the catalogs into every platform’s files; --check is the drift gate in check-rust
capsule-i18n Rust runtime: locale negotiation, message formatting, error_codes constants
Generated files Web JSON, Android strings.xml, Apple .xcstrings; committed, with a do-not-edit banner
  • locales/config.json is the closed set of supported locales: sourceLocale, supportedLocales and per-locale fallbacks. A locale ships exactly when its catalog lands and its tag enters supportedLocales.
  • locales/<locale>.json maps a key to an ICU message. en.json is the source, where every key is defined first with a required translator context. A translation entry carries its origin (Translation Provenance) and source (Translation Lifecycle) instead.
  • context states the string’s UI role (button, title, error, accessibility label), the part of speech of any word that has more than one (Crop the verb, not the noun), and the screen it appears on. A translator, human or machine, sees nothing but the message and its context.
  • Every catalog defines every source key, and generation fails when one does not. The English fallback exists for a version-skewed runtime, not as a way to ship a gap.
  • Keys use dotted namespaces (area.subarea.name) named by surface, not client. A concept present on several platforms takes no platform prefix, because the Android and Apple catalogs are generated from the same keys.

The committed language set is English plus zh-Hans, zh-Hant, ja, ko, fr, de, es, pt-BR, it, ru, hi and ar. Arabic puts RTL layout in scope for every app. Fallbacks go straight to English, so zh-Hant never falls back to zh-Hans.

Final for every app. The user’s language and their region are two separate settings:

Setting Controls Example
Language Which catalog renders UI text; text direction zh-Hant-HK (Hong Kong Traditional Chinese)
Region Formatting: dates, times, numbers, first weekday, measurement units, calendar GB (British formatting)
  • Both default from the operating system. Where the platform offers a per-app language (iOS, Android 13+), the app uses it rather than an in-app picker; elsewhere the app offers one.
  • Language selection uses the platform’s own negotiation against supportedLocales, falling back by the catalog’s fallbacks. Region never changes which strings are shown, and language never changes how a date is formatted.
  • Formatting uses each platform’s native formatters with the region. Catalog messages pass raw values (dates, counts) as arguments rather than pre-formatted text.
  • Neither setting is synced to the server; they are device preferences.

mise run i18n compiles every target. Generated files are deterministic and committed, and mise run i18n-check fails on drift. Apple and Android compile ICU plurals ahead of time to their native plural forms. The Rust runtime (capsule-i18n) has no platform ICU underneath, so it carries a small interpreter for literals, {name} interpolation and plural with CLDR integer rules. Constructs outside that subset (select, number/date skeletons, offset:) are refused rather than mis-rendered.

  • The server attaches a stable code from the catalog’s error.* namespace (for example error.auth.invalid_credentials) to every structured rejection, alongside an English detail. Clients switch on the code, never the HTTP status or the detail (Conventions — Errors).
  • Clients localize the code through their generated catalog; the detail stays English.
  • The server names codes through the generated capsule_i18n::error_codes constants, so a typo is a compile error. Error codes are catalog keys, with no second list.
  • The server never translates by Accept-Language. Localization is client-side, which keeps it offline-capable and decouples the user’s language from their server.

The CLI and TUI are not localized and will stay English-only. They are the reference client for operators and power users, and every string they add would otherwise cost thirteen catalog entries for an audience that reads English. They render the shared error.* codes through the English catalog and write their own strings inline. The apps own localization.

README.md ships as README.<lang>.md for every non-source locale in config.json. xtask translate-readme segments the README by block, takes each block’s translation from xtask/translations/readme/<locale>.json (source/target pairs), and refuses a translation that alters a link target, inline code or a glossary term. translate-readme --check fails when a committed translation no longer matches the README’s structure.

The README’s language switcher and translations table are generated from config.json (its locale order and displayNames), and --check also fails when they drift. Their progress badges read locales/stats.json, which mise run i18n writes with each locale’s share of source keys translated and reviewed (origin: human), so a catalog edit never changes the README itself.

Translators edit locales/<locale>.json and open a pull request; locales/README.md documents the format and how to add a language.

Each translation entry records who produced it, so a reviewed string is always distinguishable from one awaiting review.

origin Meaning
machine A machine translation no fluent reader has reviewed
human Written, or reviewed and accepted, by a fluent reader
  • origin is required on every translation entry and refused on the source catalog, which is authored rather than translated. A reviewer who accepts or rewrites an entry sets human.
  • The contributor and the date are the entry’s git history, not catalog fields, since a second copy in the file would drift from the commit that is the record.
  • The repository is the system of record. No hosted translation platform (Weblate, Crowdin) owns provenance; one adopted later edits these files through pull requests and keeps origin, so the record stays in git.

A translation is only as current as the English it was made from.

  • Every translation entry records source: the first 16 hex digits of the SHA-256 of the source message it translates. Generation fails when it differs from the current source message’s hash: the translation is stale.
  • A change that adds a source key or edits a source message updates every catalog in the same change, as origin: machine unless a fluent reader wrote it, with source restamped. Editing only context changes nothing downstream.
  • Machine translations ship. Human review goes first to strings whose mistranslation can lose data or lock a user out: deletion, recovery, keys and sign-in.
  • xtask i18n --todo <locale> prints the locale’s missing and stale keys with their source message and context, as JSON: the complete input for a translation pass. xtask i18n --stamp writes source into translations that lack one, and never overwrites a recorded hash.

locales/glossary.json pins terminology across catalogs.

  • verbatim lists names that are never translated or transliterated: the product, other products and standards (Capsule, TOTP, Dolby Vision). A term that appears in a source message appears unchanged in every translation of it; generation fails otherwise. A name a platform vendor localizes in its own UI (Live Photos, Wi-Fi in German) is not verbatim.
  • terms gives the preferred rendering of a domain word per locale (album, recovery key). It is the reference for a translation pass and is not checked: inflection defeats an exact match.

Every app lays out for any supported language without per-language code. The canary locales are German and Russian (longest), Arabic (right to left) and Hindi (tallest script).

  • Direction is logical. Spacing, alignment and position use leading/trailing or start/end, never left/right: SwiftUI’s leading, Compose’s start, Tailwind’s ms-/me-/ps-/pe-/start-/end-/text-start. A control that is physically directional (a media scrubber’s time axis) is the exception and carries an allowlist entry.
  • Directional icons mirror: SF Symbols’ forward/backward names, Compose’s Icons.AutoMirrored, a CSS rtl: flip on the web.
  • Components learn the direction from the app, not the page. On the web, <html dir> mirrors CSS, but Radix primitives read direction from a DirectionProvider, which the locale provider sets from the same language, so a submenu opens and arrow keys move toward the inline end.
  • Text expands. No text container has a fixed width or a fixed line height; a label wraps before it truncates, and truncates only where the platform idiom does (a list row’s secondary line). There is no per-key length limit: layout absorbs the expansion.
  • Fonts are the system’s. No app bundles a UI font. The system stack picks the correct regional Han glyphs as long as the language is declared (<html lang>, the app locale).
  • User content is isolated. An argument carrying user text (an album title, a person’s name) is bidi-isolated in the rendered message, so a Latin title inside an Arabic sentence keeps its order: BidiFormatter on Android, <bdi> on the web, the system’s isolation on Apple.

Two development-only pseudo-locales exercise the layout without a translator. Neither is in supportedLocales, and no release build offers either.

  • Expanded (en-XA): every letter accented, about 40% longer, and bracketed, [Þĥöţöš one]. A string that renders without brackets was never looked up in the catalog, and a clipped bracket is a container that did not absorb the expansion.
  • Right to left (ar-XB): English laid out as Arabic is, so mirroring can be checked by a reader who knows no Arabic.

Android generates both from strings.xml in its debug build (isPseudoLocalesEnabled). Apple uses Xcode’s double-length and right-to-left pseudolanguages, which double every catalog string (Photos Photos) and force a right-to-left layout. The web has no platform mechanism, so mise run i18n derives capsule-web/src/i18n/messages/en-XA.json and ar-XB.json from the source catalog, changing only literal text: arguments, a plural’s selector and categories, and # are left as the source has them. A development build offers both in the language picker; a production build compiles their catalogs out and ignores one left in storage, and the browser’s languages never negotiate to either.

  • Codegen is a pure function of the catalogs; i18n-check compares committed output to a fresh render.
  • Every translation carries exactly its source message’s arguments: the same {name} set, and a whole-message plural exactly where the source has one, on the same selector. Order is free and plural arms are the target language’s own. A dropped, added or retyped argument, or a key the source lacks, fails generation and so i18n-check.
  • Negotiation, interpolation, fallback and missing keys are unit-tested against fixed vectors; the CLDR plural table is asserted at boundary counts.
  • Every plural key in every catalog is rendered at boundary counts and asserted to contain no ICU syntax and to match the sentence the generated Android resource produces.
  • Generation fails on a source entry without context, a translation missing a source key, a stale or absent source, and a dropped verbatim glossary term, listing every offending key at once.
  • xtask i18n-guard refuses physical-direction layout in the app surfaces (ml-, text-left, left- on the web; chevron.left, NSTextAlignment.left in Swift; TextAlign.Left, absolutePadding in Compose; a known directional icon that does not mirror), with the same allowlist as hardcoded strings. Android lint’s RtlHardcoded, RtlSymmetry, RtlCompat and RtlEnabled are errors.
  • Every app renders its main screens under the Pseudo-locales in its own UI test framework, asserting rather than comparing images. Under the expanded pseudo-locale every visible text node must be pseudo-localized: an unmarked node is a hardcoded string the pattern scan missed. Under the right-to-left one the layout direction must reach the root and a back affordance must mirror. The web renders with bun test (the direction reaching <html dir> and Radix, and no rendered class naming a physical side), Android with Compose UI tests on a device (back at the right edge, with a left-to-right control), and Apple with XCUITest in the iPhone UI sweep (likewise). There is no golden-image gate; canary-locale screenshots are a review aid only.