Configuration
Babely uses a JSON configuration file (babely.json) to manage your translation setup. This file defines your source and target languages, as well as the files that need to be translated.
Basic Configuration
Here's a basic example in both formats:
{ "locale": { "source": "en", "targets": ["es", "fr", "de"] }, "files": { "json": { "include": ["locales/[locale].json"] } } }
Let's break down the different sections in the configuration file.
Locale Configuration
The locale section defines your translation languages:
- โsource: Your primary language for content creation (e.g., "en" for English)
- โtargets: An array of languages you want to translate into (e.g., ["es", "fr", "de"] for Spanish, French, and German)
Babely supports a wide range of language codes, including:
- โSimple codes: en, es, fr, de
- โRegion-specific codes: pt-BR, zh-CN, zh-TW
File Configuration
The files section defines which files Babely should translate. You can configure multiple file types and patterns:
JSON Files
files: { json: { include: ["locales/[locale].json"], }, }
Markdown/MDX Files
files: { md: { include: ["docs/[locale]/*.md"], }, mdx: { include: ["blog/[locale]/*.mdx"], }, }
Mobile Platform Files
For iOS (Xcode):
files: { "xcode-xcstrings": { include: ["Example/Localizable.xcstrings"], }, // Or for traditional .strings files "xcode-strings": { include: ["Example/[locale].lproj/Localizable.strings"], }, }
For Android:
files: { android: { include: ["locales/[locale].xml"], }, }
Other Formats
Here's a complete list of file formats supported by Babely:
- โJSON - Standard JSON translation files
- โYAML - YAML translation files
- โProperties - Java properties files
- โAndroid - Android XML resource files
- โiOS - iOS localization files
- โiOS Stringsdict - iOS pluralization files
- โiOS XCStrings - Modern Xcode string catalogs
- โMarkdown - Documentation files
- โMDX - Documentation with JSX
- โHTML - HTML files
- โJavaScript - JavaScript files
- โTypeScript - TypeScript files
- โGettext PO - GetText translation files
- โXLIFF - XML Localization Interchange File Format
- โCSV - Spreadsheet-based translations
- โXML - XML resource files
- โFlutter ARB - Application Resource Bundle files
- โPHP - PHP translation files
File Patterns
The [locale] placeholder in file patterns is automatically replaced with the appropriate language code during translation. For example:
- โlocales/[locale].json becomes:
- โlocales/en.json
- โlocales/es.json
- โlocales/fr.json
You can include multiple patterns for each file type and use glob patterns:
files: { json: { include: [ "src/locales/[locale].json", "src/components/[locale]/*.json" ], }, }
Project ID (Optional)
If you're using Babely's cloud services, you can include your project ID in the configuration:
{ "projectId": "prj_your_project_id", "locale": { // ... locale config }, files: { // ... files config }, }
Translation State Tracking
Babely automatically creates and maintains a babely.lock file to track the state of your translations. This file:
- โTracks which content has been translated
- โHelps identify what needs to be updated when source content changes
- โShould be committed to your version control system
You don't need to manually edit the lock file - Babely manages it automatically when you run translation commands.
Best Practices
- โVersion Control: Always commit both babely.json and babely.lock to your repository
- โFile Organization: Keep your translation files organized in a consistent directory structure
- โLanguage Codes: Use standard language codes to ensure compatibility
- โPatterns: Use specific include patterns to avoid translating unnecessary files
- โProject ID: Keep your project ID secure and don't share it publicly if you're using cloud services, use the
BABELY_PROJECT_IDenvironment variable instead.