TypeScript diagnostic messages are localized into 13 languages (including Chinese, Japanese, German, Spanish, and others) using the Microsoft Localization Studio (LCX/LCL) format. This system ensures that developers using the compiler (tsc) or the language server (tsserver) receive error messages and CLI help in their configured system language.
The localization process involves three primary file types:
diagnosticMessages.json: The source of truth for all diagnostic messages in English.src/loc/lcl/<lang>/*.lcl: Localization Library files containing the translated strings for a specific language.LCL files are XML-based documents that map English message keys (derived from the original message text and ID) to their translated counterparts.
| Component | Description |
|---|---|
| ItemId | A unique identifier combining the message name and its numeric code (e.g., ;ALL_COMPILER_OPTIONS_6917) src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl24 |
| Val (Source) | The original English text, often containing placeholders like {0} src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl35 |
| Tgt (Target) | The translated text for the specific locale src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl37 |
The following diagram illustrates how a natural language error message authored by a developer is transformed into a localized code entity within the TypeScript build artifacts.
Diagnostic Translation Pipeline
Sources: src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl24-41 scripts/generateLocalizedDiagnosticMessages.mjs1-20
The localization process is integrated into the main build pipeline managed by hereby. The build system orchestrates the generation of localized diagnostic maps that the compiler loads at runtime.
scripts/processDiagnosticMessages.mjs: Processes the base English messages and generates the initial ID mappings.scripts/generateLocalizedDiagnosticMessages.mjs: Parsers the LCL files and produces the localized output files found in the lib/ directory (e.g., lib/zh-cn/diagnosticMessages.generated.json).The build system ensures that whenever diagnosticMessages.json is updated, the corresponding localized versions are synchronized.
Build Artifact Generation
Sources: Herebyfile.mjs1-50 scripts/processDiagnosticMessages.mjs1-10 scripts/generateLocalizedDiagnosticMessages.mjs1-15
TypeScript maintains translations for the following directory structures under src/loc/lcl/:
When the compiler or language service needs to report a diagnostic, it uses the ts.Diagnostics object. If a localized bundle is available for the current environment's locale, the compiler's internal getLocaleSpecificMessage function (or equivalent logic in the host) replaces the default English string with the value extracted from the generated JSON derived from the LCL files.
Sources: src/compiler/corePublic.ts1-100 src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl1-30