Lingo.dev + .ts (TypeScript)
Lingo.dev CLI translates TypeScript locale files while preserving type definitions, object structures, and TypeScript-specific syntax. The CLI maintains TypeScript type checking and inference, supports all TypeScript syntax and features, works with default and named exports, handles template strings and interpolation correctly, and integrates seamlessly with TypeScript compilation processes.
Quick Setup
Configure for TypeScript locale files:
{
"locale": {
"source": "en",
"targets": ["es", "fr", "de"]
},
"buckets": {
"typescript": {
"include": ["src/locales/[locale].ts"]
}
}
}
Reminder: [locale]
is a placeholder that should remain in the config literally, as it's replaced with the actual locale during CLI run.
Translate TypeScript Files
npx lingo.dev@latest i18n
Preserves TypeScript syntax, type annotations, and module exports while translating string content.
TypeScript Structure Support
Default Export Requirement
For TypeScript translation to work properly, your file must export an object as the default export:
// This works - default export object
export default {
common: {
save: "Save",
cancel: "Cancel",
delete: "Delete",
},
auth: {
login: "Log In",
register: "Create Account",
},
} as const;
// This also works - variable with default export
const messages = {
welcome: "Welcome to our app",
error: "Something went wrong",
};
export default messages;
Type Safety Preservation
export const locale = {
buttons: {
submit: "Submit Form",
reset: "Reset",
},
} as const;
type LocaleKeys = typeof locale;
Type information and const assertions remain intact.
Advanced Configuration
Multiple TypeScript Files
"typescript": {
"include": [
"src/locales/[locale].ts",
"src/translations/[locale]/*.ts"
]
}
Lock Type Definitions
"typescript": {
"include": ["src/locales/[locale].ts"],
"lockedKeys": ["__type", "metadata"]
}