TypeScript
Translate literal values in static default-export locale modules while retaining surrounding TypeScript syntax.
A TypeScript locale module can keep messages close to the types that describe them. The typescript file handler translates literal values in a static default export, replacing the text in place while retaining keys, imports, comments, and surrounding type syntax. It reads the source without executing the module.
Give the handler a static catalog #
Use an inline object or array as the default export:
export default {
checkout: {
title: "Complete your order",
retries: 3,
},
steps: ["Review", "Confirm"],
} as const;String units include checkout.title, steps[0], and steps[1]. The numeric value remains unchanged. as const, satisfies, and parentheses around supported expressions can remain in the source.
Keep the translatable values literal. The handler does not resolve an exported identifier to its declaration or evaluate a factory call. It skips computed property keys, spreads, methods, and values produced by expressions. Template literals work only without interpolated expressions. If a valid module produces no translation tasks, inspect the default export's shape before looking for a translation failure.
Retain accepted values deliberately #
The previous source establishes changes by catalog path. The existing target supplies accepted values for unchanged or otherwise unresolved strings. Locked paths retain the current source literal; preserved paths retain the existing target value when available. These controls do not execute the code to discover additional text.
Replacements use the source literal's quote delimiter and escape translated content for that delimiter. A key refresh retains unselected target values. Source entries missing from that partial result can be removed, including array elements, so inspect the resulting keys and array membership before loading the module.
Configure file selection #
The CLI infers typescript for .ts, .mts, and .cts, not .js or .tsx. Select locale modules through CLI configuration or GitHub.
Load the translated module #
This format is separate from React message extraction. Extraction reads supported calls in application .ts and .tsx source to create a catalog; this handler translates an already structured locale module. See React catalogs and types for that lifecycle.
After retrieval, typecheck the module and load it through the application's catalog loader. Compare the selected keys with the messages the screen uses, then exercise placeholders. These checks reveal different problems: an invalid module cannot load, an unselected dynamic value stays untranslated, and a valid translation can still express the wrong meaning.