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
Object Export Pattern
export const messages = {
common: {
save: "Save",
cancel: "Cancel",
delete: "Delete",
},
auth: {
login: "Log In",
register: "Create Account",
},
} as const;
Interface-Based Approach
interface Messages {
welcome: string;
itemCount: (count: number) => string;
}
export const en: Messages = {
welcome: "Welcome to our platform",
itemCount: (count: number) => `You have ${count} items`,
};
Template Literal Support
export const messages = {
greeting: (name: string) => `Hello, ${name}!`,
notification: `You have ${count} new messages`,
path: `/users/${userId}/profile`,
};
Type Safety Preservation
Const Assertions
export const locale = {
buttons: {
submit: "Submit Form",
reset: "Reset",
},
} as const;
type LocaleKeys = typeof locale;
Type information and const assertions remain intact.
Function Definitions
export const t = {
welcome: (name: string): string => `Welcome, ${name}!`,
pluralize: (count: number): string =>
count === 1 ? "1 item" : `${count} items`,
};
Function signatures and return types are preserved.
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"]
}