| 1 | /** |
| 2 | * Dictionary loader for the website localization layer (#3091, #4934). |
| 3 | * |
| 4 | * Lookup is deterministic: a routed locale with a dictionary gets its own |
| 5 | * copy; every other locale gets the English reference dictionary. There is |
| 6 | * no per-key fallback chain — each shipped/partial dictionary is held to |
| 7 | * exact key parity with English by `web/scripts/check-locales.mjs` and |
| 8 | * `dictionaries.test.ts`, so a missing key is a build-time failure, never |
| 9 | * a runtime "missing marker". |
| 10 | * |
| 11 | * English resolves through the `?? enChrome` / `?? enHome` fallback rather |
| 12 | * than a map entry, which keeps `DICTIONARY_LOCALES` equal to the set of |
| 13 | * non-reference locale directories that `check-locales.mjs` walks. |
| 14 | */ |
| 15 | import type { |
| 16 | ChangelogDict, |
| 17 | ChromeDict, |
| 18 | ContributeDict, |
| 19 | ConstitutionDict, |
| 20 | RuntimeDict, |
| 21 | ComputerUseDict, |
| 22 | DocsAuthDict, |
| 23 | DocsComputersDict, |
| 24 | DocsConfigurationDict, |
| 25 | DocsFleetDict, |
| 26 | DocsGuideDict, |
| 27 | DocsHooksDict, |
| 28 | DocsMcpDict, |
| 29 | DocsRuntimeApiDict, |
| 30 | DocsSandboxDict, |
| 31 | DocsShellDict, |
| 32 | DocsModesDict, |
| 33 | DocsReviewDict, |
| 34 | DocsVocabularyDict, |
| 35 | DocsSubagentsDict, |
| 36 | DocsTroubleshootingDict, |
| 37 | DocsTrustDict, |
| 38 | DocsWebDict, |
| 39 | DocsWorkDict, |
| 40 | HomeDict, |
| 41 | DigestDict, |
| 42 | FeedDict, |
| 43 | CommunityDict, |
| 44 | FaqDict, |
| 45 | LegalPrivacyDict, |
| 46 | LegalTermsDict, |
| 47 | RoadmapDict, |
| 48 | StatesDict, |
| 49 | } from "./types"; |
| 50 | import { chrome as enChrome } from "./en/chrome"; |
| 51 | import { home as enHome } from "./en/home"; |
| 52 | import { docsGuide as enDocsGuide } from "./en/docs-guide"; |
| 53 | import { docsGuide as zhDocsGuide } from "./zh/docs-guide"; |
| 54 | import { docsShell as enDocsShell } from "./en/docs-shell"; |
| 55 | import { docsShell as zhDocsShell } from "./zh/docs-shell"; |
| 56 | import { docsHooks as enDocsHooks } from "./en/docs-hooks"; |
| 57 | import { docsHooks as zhDocsHooks } from "./zh/docs-hooks"; |
| 58 | import { docsTroubleshooting as enDocsTroubleshooting } from "./en/docs-troubleshooting"; |
| 59 | import { docsTroubleshooting as zhDocsTroubleshooting } from "./zh/docs-troubleshooting"; |
| 60 | import { docsConfiguration as enDocsConfiguration } from "./en/docs-configuration"; |
| 61 | import { docsConfiguration as zhDocsConfiguration } from "./zh/docs-configuration"; |
| 62 | import { docsFleet as enDocsFleet } from "./en/docs-fleet"; |
| 63 | import { docsFleet as zhDocsFleet } from "./zh/docs-fleet"; |
| 64 | import { docsMcp as enDocsMcp } from "./en/docs-mcp"; |
| 65 | import { docsMcp as zhDocsMcp } from "./zh/docs-mcp"; |
| 66 | import { docsModes as enDocsModes } from "./en/docs-modes"; |
| 67 | import { docsModes as zhDocsModes } from "./zh/docs-modes"; |
| 68 | import { docsRuntimeApi as enDocsRuntimeApi } from "./en/docs-runtime-api"; |
| 69 | import { docsRuntimeApi as zhDocsRuntimeApi } from "./zh/docs-runtime-api"; |
| 70 | import { docsSandbox as enDocsSandbox } from "./en/docs-sandbox"; |
| 71 | import { docsSandbox as zhDocsSandbox } from "./zh/docs-sandbox"; |
| 72 | import { docsSubagents as enDocsSubagents } from "./en/docs-subagents"; |
| 73 | import { docsSubagents as zhDocsSubagents } from "./zh/docs-subagents"; |
| 74 | import { docsWeb as enDocsWeb } from "./en/docs-web"; |
| 75 | import { docsWeb as zhDocsWeb } from "./zh/docs-web"; |
| 76 | import { docsWork as enDocsWork } from "./en/docs-work"; |
| 77 | import { docsWork as zhDocsWork } from "./zh/docs-work"; |
| 78 | import { docsComputers as enDocsComputers } from "./en/docs-computers"; |
| 79 | import { docsComputers as zhDocsComputers } from "./zh/docs-computers"; |
| 80 | import { docsAuth as enDocsAuth } from "./en/docs-auth"; |
| 81 | import { docsAuth as zhDocsAuth } from "./zh/docs-auth"; |
| 82 | import { docsTrust as enDocsTrust } from "./en/docs-trust"; |
| 83 | import { docsTrust as zhDocsTrust } from "./zh/docs-trust"; |
| 84 | import { docsReview as enDocsReview } from "./en/docs-review"; |
| 85 | import { docsReview as zhDocsReview } from "./zh/docs-review"; |
| 86 | import { docsVocabulary as enDocsVocabulary } from "./en/docs-vocabulary"; |
| 87 | import { docsVocabulary as zhDocsVocabulary } from "./zh/docs-vocabulary"; |
| 88 | import { computerUse as enComputerUse } from "./en/computer-use"; |
| 89 | import { computerUse as zhComputerUse } from "./zh/computer-use"; |
| 90 | import { computerUse as jaComputerUse } from "./ja/computer-use"; |
| 91 | import { computerUse as viComputerUse } from "./vi/computer-use"; |
| 92 | import { computerUse as koComputerUse } from "./ko/computer-use"; |
| 93 | import { computerUse as ruComputerUse } from "./ru/computer-use"; |
| 94 | import { computerUse as ukComputerUse } from "./uk/computer-use"; |
| 95 | import { computerUse as esComputerUse } from "./es/computer-use"; |
| 96 | import { computerUse as frComputerUse } from "./fr/computer-use"; |
| 97 | import { computerUse as deComputerUse } from "./de/computer-use"; |
| 98 | import { computerUse as caComputerUse } from "./ca/computer-use"; |
| 99 | import { computerUse as hiComputerUse } from "./hi/computer-use"; |
| 100 | import { computerUse as trComputerUse } from "./tr/computer-use"; |
| 101 | import { computerUse as itComputerUse } from "./it/computer-use"; |
| 102 | import { computerUse as plComputerUse } from "./pl/computer-use"; |
| 103 | import { computerUse as arComputerUse } from "./ar/computer-use"; |
| 104 | import { computerUse as ptBrComputerUse } from "./pt-BR/computer-use"; |
| 105 | import { computerUse as idComputerUse } from "./id/computer-use"; |
| 106 | import { states as enStates } from "./en/states"; |
| 107 | import { states as zhStates } from "./zh/states"; |
| 108 | import { changelog as enChangelog } from "./en/changelog"; |
| 109 | import { changelog as zhChangelog } from "./zh/changelog"; |
| 110 | import { legalTerms as enLegalTerms } from "./en/legal-terms"; |
| 111 | import { legalTerms as zhLegalTerms } from "./zh/legal-terms"; |
| 112 | import { legalPrivacy as enLegalPrivacy } from "./en/legal-privacy"; |
| 113 | import { legalPrivacy as zhLegalPrivacy } from "./zh/legal-privacy"; |
| 114 | import { digest as enDigest } from "./en/digest"; |
| 115 | import { digest as zhDigest } from "./zh/digest"; |
| 116 | import { feed as enFeed } from "./en/feed"; |
| 117 | import { feed as zhFeed } from "./zh/feed"; |
| 118 | import { community as enCommunity } from "./en/community"; |
| 119 | import { community as zhCommunity } from "./zh/community"; |
| 120 | import { faq as enFaq } from "./en/faq"; |
| 121 | import { faq as zhFaq } from "./zh/faq"; |
| 122 | import { roadmap as enRoadmap } from "./en/roadmap"; |
| 123 | import { roadmap as zhRoadmap } from "./zh/roadmap"; |
| 124 | import { contribute as enContribute } from "./en/contribute"; |
| 125 | import { contribute as zhContribute } from "./zh/contribute"; |
| 126 | import { constitution as enConstitution } from "./en/constitution"; |
| 127 | import { constitution as zhConstitution } from "./zh/constitution"; |
| 128 | import { runtime as enRuntime } from "./en/runtime"; |
| 129 | import { runtime as zhRuntime } from "./zh/runtime"; |
| 130 | import { chrome as zhChrome } from "./zh/chrome"; |
| 131 | import { home as zhHome } from "./zh/home"; |
| 132 | import { chrome as jaChrome } from "./ja/chrome"; |
| 133 | import { home as jaHome } from "./ja/home"; |
| 134 | import { chrome as viChrome } from "./vi/chrome"; |
| 135 | import { home as viHome } from "./vi/home"; |
| 136 | import { chrome as koChrome } from "./ko/chrome"; |
| 137 | import { home as koHome } from "./ko/home"; |
| 138 | import { chrome as ruChrome } from "./ru/chrome"; |
| 139 | import { home as ruHome } from "./ru/home"; |
| 140 | import { chrome as ukChrome } from "./uk/chrome"; |
| 141 | import { home as ukHome } from "./uk/home"; |
| 142 | import { chrome as esChrome } from "./es/chrome"; |
| 143 | import { home as esHome } from "./es/home"; |
| 144 | import { chrome as frChrome } from "./fr/chrome"; |
| 145 | import { home as frHome } from "./fr/home"; |
| 146 | import { docsGuide as frDocsGuide } from "./fr/docs-guide"; |
| 147 | import { chrome as deChrome } from "./de/chrome"; |
| 148 | import { home as deHome } from "./de/home"; |
| 149 | import { docsGuide as deDocsGuide } from "./de/docs-guide"; |
| 150 | import { chrome as caChrome } from "./ca/chrome"; |
| 151 | import { home as caHome } from "./ca/home"; |
| 152 | import { docsGuide as caDocsGuide } from "./ca/docs-guide"; |
| 153 | import { chrome as hiChrome } from "./hi/chrome"; |
| 154 | import { home as hiHome } from "./hi/home"; |
| 155 | import { docsGuide as hiDocsGuide } from "./hi/docs-guide"; |
| 156 | import { chrome as trChrome } from "./tr/chrome"; |
| 157 | import { home as trHome } from "./tr/home"; |
| 158 | import { docsGuide as trDocsGuide } from "./tr/docs-guide"; |
| 159 | import { chrome as itChrome } from "./it/chrome"; |
| 160 | import { home as itHome } from "./it/home"; |
| 161 | import { docsGuide as itDocsGuide } from "./it/docs-guide"; |
| 162 | import { chrome as plChrome } from "./pl/chrome"; |
| 163 | import { home as plHome } from "./pl/home"; |
| 164 | import { docsGuide as plDocsGuide } from "./pl/docs-guide"; |
| 165 | import { chrome as arChrome } from "./ar/chrome"; |
| 166 | import { home as arHome } from "./ar/home"; |
| 167 | import { docsGuide as arDocsGuide } from "./ar/docs-guide"; |
| 168 | import { chrome as ptBrChrome } from "./pt-BR/chrome"; |
| 169 | import { home as ptBrHome } from "./pt-BR/home"; |
| 170 | import { chrome as idChrome } from "./id/chrome"; |
| 171 | import { home as idHome } from "./id/home"; |
| 172 | |
| 173 | const CHROME: Record<string, ChromeDict> = { |
| 174 | zh: zhChrome, |
| 175 | ja: jaChrome, |
| 176 | vi: viChrome, |
| 177 | ko: koChrome, |
| 178 | ru: ruChrome, |
| 179 | uk: ukChrome, |
| 180 | es: esChrome, |
| 181 | fr: frChrome, |
| 182 | de: deChrome, |
| 183 | ca: caChrome, |
| 184 | hi: hiChrome, |
| 185 | tr: trChrome, |
| 186 | it: itChrome, |
| 187 | pl: plChrome, |
| 188 | ar: arChrome, |
| 189 | "pt-BR": ptBrChrome, |
| 190 | id: idChrome, |
| 191 | }; |
| 192 | |
| 193 | const HOME: Record<string, HomeDict> = { |
| 194 | zh: zhHome, |
| 195 | ja: jaHome, |
| 196 | vi: viHome, |
| 197 | ko: koHome, |
| 198 | ru: ruHome, |
| 199 | uk: ukHome, |
| 200 | es: esHome, |
| 201 | fr: frHome, |
| 202 | de: deHome, |
| 203 | ca: caHome, |
| 204 | hi: hiHome, |
| 205 | tr: trHome, |
| 206 | it: itHome, |
| 207 | pl: plHome, |
| 208 | ar: arHome, |
| 209 | "pt-BR": ptBrHome, |
| 210 | id: idHome, |
| 211 | }; |
| 212 | |
| 213 | /** Locales with their own dictionary directory (English is the reference). */ |
| 214 | export const DICTIONARY_LOCALES = Object.keys(CHROME) as readonly string[]; |
| 215 | |
| 216 | /** |
| 217 | * Per-page dictionaries (#5337). Unlike chrome/home, a page dictionary is |
| 218 | * optional per locale: English is the required reference, any locale that |
| 219 | * ships the file is held to exact key parity, and everyone else falls back |
| 220 | * to English here — the same behavior page bodies already had for partial |
| 221 | * locales, now expressed through one lookup instead of an `isZh` ternary. |
| 222 | */ |
| 223 | const DOCS_GUIDE: Record<string, DocsGuideDict> = { |
| 224 | zh: zhDocsGuide, |
| 225 | fr: frDocsGuide, |
| 226 | de: deDocsGuide, |
| 227 | ca: caDocsGuide, |
| 228 | hi: hiDocsGuide, |
| 229 | tr: trDocsGuide, |
| 230 | it: itDocsGuide, |
| 231 | pl: plDocsGuide, |
| 232 | ar: arDocsGuide, |
| 233 | }; |
| 234 | |
| 235 | const DOCS_SHELL: Record<string, DocsShellDict> = { |
| 236 | zh: zhDocsShell, |
| 237 | }; |
| 238 | |
| 239 | const DOCS_HOOKS: Record<string, DocsHooksDict> = { |
| 240 | zh: zhDocsHooks, |
| 241 | }; |
| 242 | |
| 243 | const DOCS_TROUBLESHOOTING: Record<string, DocsTroubleshootingDict> = { |
| 244 | zh: zhDocsTroubleshooting, |
| 245 | }; |
| 246 | |
| 247 | const DOCS_CONFIGURATION: Record<string, DocsConfigurationDict> = { |
| 248 | zh: zhDocsConfiguration, |
| 249 | }; |
| 250 | |
| 251 | const DOCS_FLEET: Record<string, DocsFleetDict> = { |
| 252 | zh: zhDocsFleet, |
| 253 | }; |
| 254 | |
| 255 | const DOCS_MCP: Record<string, DocsMcpDict> = { |
| 256 | zh: zhDocsMcp, |
| 257 | }; |
| 258 | |
| 259 | const DOCS_MODES: Record<string, DocsModesDict> = { |
| 260 | zh: zhDocsModes, |
| 261 | }; |
| 262 | |
| 263 | const DOCS_RUNTIME_API: Record<string, DocsRuntimeApiDict> = { |
| 264 | zh: zhDocsRuntimeApi, |
| 265 | }; |
| 266 | |
| 267 | const DOCS_SANDBOX: Record<string, DocsSandboxDict> = { |
| 268 | zh: zhDocsSandbox, |
| 269 | }; |
| 270 | |
| 271 | const DOCS_SUBAGENTS: Record<string, DocsSubagentsDict> = { |
| 272 | zh: zhDocsSubagents, |
| 273 | }; |
| 274 | |
| 275 | const DOCS_WEB: Record<string, DocsWebDict> = { |
| 276 | zh: zhDocsWeb, |
| 277 | }; |
| 278 | |
| 279 | const DOCS_WORK: Record<string, DocsWorkDict> = { |
| 280 | zh: zhDocsWork, |
| 281 | }; |
| 282 | |
| 283 | const DOCS_COMPUTERS: Record<string, DocsComputersDict> = { |
| 284 | zh: zhDocsComputers, |
| 285 | }; |
| 286 | |
| 287 | const DOCS_AUTH: Record<string, DocsAuthDict> = { |
| 288 | zh: zhDocsAuth, |
| 289 | }; |
| 290 | |
| 291 | const COMPUTER_USE: Record<string, ComputerUseDict> = { |
| 292 | zh: zhComputerUse, |
| 293 | ja: jaComputerUse, |
| 294 | vi: viComputerUse, |
| 295 | ko: koComputerUse, |
| 296 | ru: ruComputerUse, |
| 297 | uk: ukComputerUse, |
| 298 | es: esComputerUse, |
| 299 | fr: frComputerUse, |
| 300 | de: deComputerUse, |
| 301 | ca: caComputerUse, |
| 302 | hi: hiComputerUse, |
| 303 | tr: trComputerUse, |
| 304 | it: itComputerUse, |
| 305 | pl: plComputerUse, |
| 306 | ar: arComputerUse, |
| 307 | "pt-BR": ptBrComputerUse, |
| 308 | id: idComputerUse, |
| 309 | }; |
| 310 | |
| 311 | const DOCS_TRUST: Record<string, DocsTrustDict> = { |
| 312 | zh: zhDocsTrust, |
| 313 | }; |
| 314 | |
| 315 | const DOCS_REVIEW: Record<string, DocsReviewDict> = { |
| 316 | zh: zhDocsReview, |
| 317 | }; |
| 318 | |
| 319 | const DOCS_VOCABULARY: Record<string, DocsVocabularyDict> = { |
| 320 | zh: zhDocsVocabulary, |
| 321 | }; |
| 322 | |
| 323 | /** |
| 324 | * Shared surface states, the changelog page, the two legal pages, the digest, |
| 325 | * feed and community pages, the FAQ, the roadmap, and the contribute, |
| 326 | * constitution and runtime pages follow the same optional per-locale rule as |
| 327 | * the docs page dictionaries: English is the reference, every other locale |
| 328 | * falls back to it at lookup time. |
| 329 | */ |
| 330 | const STATES: Record<string, StatesDict> = { |
| 331 | zh: zhStates, |
| 332 | }; |
| 333 | |
| 334 | const CHANGELOG: Record<string, ChangelogDict> = { |
| 335 | zh: zhChangelog, |
| 336 | }; |
| 337 | |
| 338 | const LEGAL_TERMS: Record<string, LegalTermsDict> = { |
| 339 | zh: zhLegalTerms, |
| 340 | }; |
| 341 | |
| 342 | const LEGAL_PRIVACY: Record<string, LegalPrivacyDict> = { |
| 343 | zh: zhLegalPrivacy, |
| 344 | }; |
| 345 | |
| 346 | const DIGEST: Record<string, DigestDict> = { |
| 347 | zh: zhDigest, |
| 348 | }; |
| 349 | |
| 350 | const FEED: Record<string, FeedDict> = { |
| 351 | zh: zhFeed, |
| 352 | }; |
| 353 | |
| 354 | const COMMUNITY: Record<string, CommunityDict> = { |
| 355 | zh: zhCommunity, |
| 356 | }; |
| 357 | |
| 358 | const FAQ: Record<string, FaqDict> = { |
| 359 | zh: zhFaq, |
| 360 | }; |
| 361 | |
| 362 | const ROADMAP: Record<string, RoadmapDict> = { |
| 363 | zh: zhRoadmap, |
| 364 | }; |
| 365 | |
| 366 | const CONTRIBUTE: Record<string, ContributeDict> = { |
| 367 | zh: zhContribute, |
| 368 | }; |
| 369 | |
| 370 | const CONSTITUTION: Record<string, ConstitutionDict> = { |
| 371 | zh: zhConstitution, |
| 372 | }; |
| 373 | |
| 374 | const RUNTIME: Record<string, RuntimeDict> = { |
| 375 | zh: zhRuntime, |
| 376 | }; |
| 377 | |
| 378 | export function getChrome(locale: string): ChromeDict { |
| 379 | return CHROME[locale] ?? enChrome; |
| 380 | } |
| 381 | |
| 382 | export function getHome(locale: string): HomeDict { |
| 383 | return HOME[locale] ?? enHome; |
| 384 | } |
| 385 | |
| 386 | export function getDocsGuide(locale: string): DocsGuideDict { |
| 387 | return DOCS_GUIDE[locale] ?? enDocsGuide; |
| 388 | } |
| 389 | |
| 390 | export function getDocsShell(locale: string): DocsShellDict { |
| 391 | return DOCS_SHELL[locale] ?? enDocsShell; |
| 392 | } |
| 393 | |
| 394 | export function getDocsHooks(locale: string): DocsHooksDict { |
| 395 | return DOCS_HOOKS[locale] ?? enDocsHooks; |
| 396 | } |
| 397 | |
| 398 | export function getDocsTroubleshooting(locale: string): DocsTroubleshootingDict { |
| 399 | return DOCS_TROUBLESHOOTING[locale] ?? enDocsTroubleshooting; |
| 400 | } |
| 401 | |
| 402 | export function getDocsConfiguration(locale: string): DocsConfigurationDict { |
| 403 | return DOCS_CONFIGURATION[locale] ?? enDocsConfiguration; |
| 404 | } |
| 405 | |
| 406 | export function getDocsFleet(locale: string): DocsFleetDict { |
| 407 | return DOCS_FLEET[locale] ?? enDocsFleet; |
| 408 | } |
| 409 | |
| 410 | export function getDocsMcp(locale: string): DocsMcpDict { |
| 411 | return DOCS_MCP[locale] ?? enDocsMcp; |
| 412 | } |
| 413 | |
| 414 | export function getDocsModes(locale: string): DocsModesDict { |
| 415 | return DOCS_MODES[locale] ?? enDocsModes; |
| 416 | } |
| 417 | |
| 418 | export function getDocsRuntimeApi(locale: string): DocsRuntimeApiDict { |
| 419 | return DOCS_RUNTIME_API[locale] ?? enDocsRuntimeApi; |
| 420 | } |
| 421 | |
| 422 | export function getDocsSandbox(locale: string): DocsSandboxDict { |
| 423 | return DOCS_SANDBOX[locale] ?? enDocsSandbox; |
| 424 | } |
| 425 | |
| 426 | export function getDocsSubagents(locale: string): DocsSubagentsDict { |
| 427 | return DOCS_SUBAGENTS[locale] ?? enDocsSubagents; |
| 428 | } |
| 429 | |
| 430 | export function getDocsWeb(locale: string): DocsWebDict { |
| 431 | return DOCS_WEB[locale] ?? enDocsWeb; |
| 432 | } |
| 433 | |
| 434 | export function getDocsWork(locale: string): DocsWorkDict { |
| 435 | return DOCS_WORK[locale] ?? enDocsWork; |
| 436 | } |
| 437 | |
| 438 | export function getDocsComputers(locale: string): DocsComputersDict { |
| 439 | return DOCS_COMPUTERS[locale] ?? enDocsComputers; |
| 440 | } |
| 441 | |
| 442 | export function getDocsAuth(locale: string): DocsAuthDict { |
| 443 | return DOCS_AUTH[locale] ?? enDocsAuth; |
| 444 | } |
| 445 | |
| 446 | export function getDocsTrust(locale: string): DocsTrustDict { |
| 447 | return DOCS_TRUST[locale] ?? enDocsTrust; |
| 448 | } |
| 449 | |
| 450 | export function getDocsReview(locale: string): DocsReviewDict { |
| 451 | return DOCS_REVIEW[locale] ?? enDocsReview; |
| 452 | } |
| 453 | |
| 454 | export function getDocsVocabulary(locale: string): DocsVocabularyDict { |
| 455 | return DOCS_VOCABULARY[locale] ?? enDocsVocabulary; |
| 456 | } |
| 457 | |
| 458 | export function getComputerUse(locale: string): ComputerUseDict { |
| 459 | return COMPUTER_USE[locale] ?? enComputerUse; |
| 460 | } |
| 461 | |
| 462 | /** |
| 463 | * Locales whose /computer-use page body is translated (the page renders only |
| 464 | * from this dictionary). The content-locale registry derives canonical, |
| 465 | * hreflang and sitemap coverage from it, so they cannot drift apart. |
| 466 | */ |
| 467 | export function hasComputerUseTranslation(locale: string): boolean { |
| 468 | return locale === "en" || Object.hasOwn(COMPUTER_USE, locale); |
| 469 | } |
| 470 | |
| 471 | export function getStates(locale: string): StatesDict { |
| 472 | return STATES[locale] ?? enStates; |
| 473 | } |
| 474 | |
| 475 | export function getChangelog(locale: string): ChangelogDict { |
| 476 | return CHANGELOG[locale] ?? enChangelog; |
| 477 | } |
| 478 | |
| 479 | export function getLegalTerms(locale: string): LegalTermsDict { |
| 480 | return LEGAL_TERMS[locale] ?? enLegalTerms; |
| 481 | } |
| 482 | |
| 483 | export function getLegalPrivacy(locale: string): LegalPrivacyDict { |
| 484 | return LEGAL_PRIVACY[locale] ?? enLegalPrivacy; |
| 485 | } |
| 486 | |
| 487 | export function getDigest(locale: string): DigestDict { |
| 488 | return DIGEST[locale] ?? enDigest; |
| 489 | } |
| 490 | |
| 491 | export function getFeed(locale: string): FeedDict { |
| 492 | return FEED[locale] ?? enFeed; |
| 493 | } |
| 494 | |
| 495 | export function getCommunity(locale: string): CommunityDict { |
| 496 | return COMMUNITY[locale] ?? enCommunity; |
| 497 | } |
| 498 | |
| 499 | export function getFaq(locale: string): FaqDict { |
| 500 | return FAQ[locale] ?? enFaq; |
| 501 | } |
| 502 | |
| 503 | export function getRoadmap(locale: string): RoadmapDict { |
| 504 | return ROADMAP[locale] ?? enRoadmap; |
| 505 | } |
| 506 | |
| 507 | export function getContribute(locale: string): ContributeDict { |
| 508 | return CONTRIBUTE[locale] ?? enContribute; |
| 509 | } |
| 510 | |
| 511 | export function getConstitution(locale: string): ConstitutionDict { |
| 512 | return CONSTITUTION[locale] ?? enConstitution; |
| 513 | } |
| 514 | |
| 515 | export function getRuntime(locale: string): RuntimeDict { |
| 516 | return RUNTIME[locale] ?? enRuntime; |
| 517 | } |
| 518 | |
| 519 | /** |
| 520 | * Select one side of a legacy `{ en, zh }` content pair by locale. This is |
| 521 | * the transitional bridge for `web/lib/content/` modules that still carry |
| 522 | * two-language pairs (#5337 Phase 3 dissolves them into dictionaries): it |
| 523 | * moves the branch out of page TSX and into the i18n layer, so call sites |
| 524 | * stay locale-agnostic. |
| 525 | */ |
| 526 | export function pickText(pair: { en: string; zh: string }, locale: string): string { |
| 527 | return pair[pickTextLocale(locale)]; |
| 528 | } |
| 529 | |
| 530 | /** The actual language selected by the legacy two-language content bridge. */ |
| 531 | export function pickTextLocale(locale: string): "en" | "zh" { |
| 532 | return locale === "zh" ? "zh" : "en"; |
| 533 | } |
| 534 | |
| 535 | /** Reference dictionaries (parity baseline for the locale checks). */ |
| 536 | export const EN_CHROME = enChrome; |
| 537 | export const EN_HOME = enHome; |
| 538 | export const EN_DOCS_GUIDE = enDocsGuide; |
| 539 | export const EN_DOCS_SHELL = enDocsShell; |
| 540 | export const EN_DOCS_HOOKS = enDocsHooks; |
| 541 | export const EN_DOCS_TROUBLESHOOTING = enDocsTroubleshooting; |
| 542 | export const EN_DOCS_CONFIGURATION = enDocsConfiguration; |
| 543 | export const EN_DOCS_FLEET = enDocsFleet; |
| 544 | export const EN_DOCS_MCP = enDocsMcp; |
| 545 | export const EN_DOCS_MODES = enDocsModes; |
| 546 | export const EN_DOCS_RUNTIME_API = enDocsRuntimeApi; |
| 547 | export const EN_DOCS_SANDBOX = enDocsSandbox; |
| 548 | export const EN_DOCS_SUBAGENTS = enDocsSubagents; |
| 549 | export const EN_DOCS_WEB = enDocsWeb; |
| 550 | export const EN_DOCS_WORK = enDocsWork; |
| 551 | export const EN_DOCS_COMPUTERS = enDocsComputers; |
| 552 | export const EN_DOCS_AUTH = enDocsAuth; |
| 553 | export const EN_DOCS_TRUST = enDocsTrust; |
| 554 | export const EN_DOCS_REVIEW = enDocsReview; |
| 555 | export const EN_DOCS_VOCABULARY = enDocsVocabulary; |
| 556 | export const EN_COMPUTER_USE = enComputerUse; |
| 557 | export const EN_STATES = enStates; |
| 558 | export const EN_CHANGELOG = enChangelog; |
| 559 | export const EN_LEGAL_TERMS = enLegalTerms; |
| 560 | export const EN_LEGAL_PRIVACY = enLegalPrivacy; |
| 561 | export const EN_DIGEST = enDigest; |
| 562 | export const EN_FEED = enFeed; |
| 563 | export const EN_COMMUNITY = enCommunity; |
| 564 | export const EN_FAQ = enFaq; |
| 565 | export const EN_ROADMAP = enRoadmap; |
| 566 | export const EN_CONTRIBUTE = enContribute; |
| 567 | export const EN_CONSTITUTION = enConstitution; |
| 568 | export const EN_RUNTIME = enRuntime; |
| 569 | |
| 570 | /** Interpolate `{name}` tokens in a dictionary template. Unknown tokens are |
| 571 | * left intact so a template/variable drift is visible in review, not silent. */ |
| 572 | export function fill(template: string, vars: Record<string, string | number>): string { |
| 573 | return template.replace(/\{(\w+)\}/g, (match, name: string) => |
| 574 | name in vars ? String(vars[name]) : match, |
| 575 | ); |
| 576 | } |
| 577 | |
| 578 | /** |
| 579 | * Split a template on a single `{token}` so a call site can typeset the |
| 580 | * substituted value as its own element without concatenating translated |
| 581 | * fragments around it. Returns the literal parts in template order — the |
| 582 | * caller interleaves its node between them, so a locale that puts the token |
| 583 | * in a different position still renders correctly. |
| 584 | */ |
| 585 | export function splitToken(template: string, token: string): string[] { |
| 586 | return template.split(`{${token}}`); |
| 587 | } |
| 588 | |
| 589 |