TypeScript
Babely supports TypeScript localization files with full type safety. This format extends JavaScript support with additional TypeScript-specific features and type generation capabilities.
Setting Up
First, make sure you've got a babely.json config file in your project root. Here's an example:
typescript
{ "locale": { "source": "en", "targets": ["sv", "de", "fr"] }, "files": { "ts": { "include": ["src/locales/[locale].ts"] } } }
Translating
With your config set, run:
typescript
npx babely@latest translate
When you run this command, Babely will:
- ◇Load your source TypeScript files (e.g., src/locales/en.ts)
- ◇Detect any new or modified translation strings
- ◇Generate translations for your target languages
- ◇Create or update the target language files (e.g., src/locales/sv.ts)
- ◇Preserve type annotations and interfaces
- ◇Handle nested objects with proper typing
- ◇Maintain code formatting and documentation comments
- ◇Support literal types and union types