concept

Localization fallback ($t() / locale keys)

Most content on a DocC-rendered page is author-written text embedded directly on the wire and rendered verbatim — there's nothing to translate. But a fixed set of chrome strings that DocC itself generates rather than the author — an aside's default label ("Note", "Warning"), a button's accessible name, a "Language" picker's options — are never present on the wire at all; they're looked up at render time from a locale file by a fixed key, with English as the runtime fallback. Fullest single-kind treatment prior to this page: block-aside.html, which documents the aside-kind.<kind> key family in depth.

1. How swift-docc-render consumes this

The mechanism is Vue-i18n, wired up once at app startup in src/setup-utils/SwiftDocCRenderi18n.js, which constructs one shared VueI18n instance:

const i18n = new VueI18n({
  locale: defaultLocale,
  fallbackLocale: defaultLocale,
  messages: { [defaultLocale]: enUS },
  silentFallbackWarn: true,
});

(Paraphrased from SwiftDocCRenderi18n.js.) defaultLocale is "en-US" and doubles as the fallbackLocale — meaning that no matter which locale is active, a missing key in that locale's message file always resolves to the English string rather than rendering a raw key or empty text. Additional locale bundles under src/lang/locales/{ar,ja-JP,ko-KR,zh-CN}.json are loaded on demand via updateLocale() (src/utils/i18n-utils.js) when the app detects a different preferred language, merging that locale's messages into the same VueI18n instance rather than replacing it wholesale — which is why a translation gap in, say, the Japanese bundle degrades to English for just that one string rather than breaking the rest of the page.

Every component that needs one of these chrome strings calls the injected $t(key) method directly in its template or a computed property — there's no central registry of which components use which keys, and no build-time check that a referenced key exists in every locale file (a typo in a key name resolves silently to the fallback locale's value for that key, or to Vue-i18n's own missing-key handling if it's absent from every locale, since silentFallbackWarn suppresses console warnings for the common case of a locale simply not having translated a string yet). The aside-kind.<kind> lookup on block-aside.html is the clearest example of the pattern:

label: ({ kind }) => `aside-kind.${kind}`,
// in the template:
// {{ name || $t(label) }}

— the wire payload's own name field always wins when present; $t() is consulted only as a fallback when the author didn't supply an explicit label, which is the common case since most asides are written as plain > Note:/> Warning: Markdown with no custom name.

2. Worked example: two different key families

Two real, unrelated components illustrate the same fallback shape. The first is the aside label covered in full on block-aside.html:

// English locale (src/lang/locales/en-US.json), excerpt:
{
  "aside-kind": {
    "note": "Note", "tip": "Tip", "experiment": "Experiment",
    "important": "Important", "warning": "Warning", "deprecated": "Deprecated", "beta": "Beta"
  }
}

The second is ReplayableVideoAsset.vue's custom video controls (see reference-video.html §4), which read several video.* keys purely for accessibility — none of them ever appear as visible text, only as aria-label/aria-labelledby targets for screen readers:

{
  "video": {
    "play": "Play", "pause": "Pause", "replay": "Replay",
    "title": "Video", "custom-controls": "Video controls", "description": "Video description"
  }
}

Both families follow the identical shape: a nested JSON object under one namespace key (aside-kind, video), each leaf a plain English string, looked up via $t("aside-kind.note") / $t("video.play") respectively. Swap the active locale to ja-JP and, if that bundle has translated aside-kind.note but not yet video.play, the aside label renders in Japanese while the video button's accessible name silently falls back to the English fallbackLocale string — two independently partial translations, resolved key-by-key rather than file-by-file.

3. Data sheet

This mechanism has no wire-schema representation at all — it's purely a swift-docc-render runtime concern, not a RenderNode field, so there is no corresponding entry in Sources/DocCArchive/Vendored/RenderNode.spec.json or generated Swift type. What's "documented" here instead is the shape of the locale JSON files themselves (src/lang/locales/{en-US,ar,ja-JP,ko-KR,zh-CN}.json) and the two functions that manage them: createI18n()/the module-level i18n singleton in SwiftDocCRenderi18n.js (constructs the VueI18n instance with en-US as both default and fallback locale), and updateLocale(locale) in i18n-utils.js (fetches and merges an additional locale bundle into the running instance when the app's detected preferred language changes, without discarding what's already loaded).

Because this is purely a rendering-time concern with no wire representation, it's also entirely invisible to any archive-level tooling: neither indexing-records.json's full-text index nor linkable-entities.json's summaries (see Archive Structure) capture these strings in any locale other than whichever one was active when docc convert ran — the localized UI chrome is generated fresh by the browser at view time, not baked into the archive per-locale.

4. Where else this shows up

Beyond the aside-label and video-controls families above, the same $t(key) pattern covers a wide range of UI chrome scattered across many kinds: accessibility strings on attributes, parameters, possible-values, and REST body section headers; call-to-action button labels on call-to-action; relationship-graph labels on relationships; download-button text on download; and screen-reader-only strikethrough announcement text on strikethrough. In every case the pattern is the same: the wire JSON never carries the localized string itself, only the data needed to pick the right lookup key (a kind/role/type discriminator, or nothing at all for a context-independent string like "Play").

5. Modern CSS-only alternative

Not applicable

Locale-string lookup with a fallback chain is fundamentally a data-selection problem (which of N translated strings should render for this key, given the active locale and what that locale's bundle actually contains) — there is no CSS mechanism that selects between arbitrary text content based on an app-level locale preference. The closest native primitive, the :lang() pseudo-class, can style text differently per language but cannot supply the different text itself the way $t() does; some engines support content: attr(data-i18n-note)-style substitution, but that still requires every localized string to be pre-rendered into a per-element data attribute at build/render time, which is exactly the JS-side lookup this mechanism already performs, not a CSS-only replacement for it.