i18nize
🧠 Automatically fills in missing I18n YAML keys using DeepL translation API. Designed to streamline multi-language support in Ruby and Rails projects.
✨ Features
- Detects missing or empty translation keys in locale files
- Supports multiple YAML files and nested directories (e.g.
config/locales/api/en.yml
) - Automatically translates from a source locale (default:
en
) to a target (e.g.cs
) - Integrates with DeepL API (Free or Pro)
- Safely merges translations into corresponding
*.yml
files - Handles structural conflicts by overwriting target with source truth
- Character count check with confirmation prompt
- CLI (
i18nize
)
🔧 Installation
Add this line to your application's Gemfile:
gem "i18nize"
Then run:
bundle install
Or install manually:
gem install i18nize
🚀 Usage
1. Set your DeepL API key
Create a .env
file (loaded automatically if you use dotenv
) or export it in your shell:
export DEEPL_API_KEY=your-api-key
export DEEPL_ENDPOINT=https://api.deepl.com/v2/translate # Only if you are using a DeepL Pro account
👉 You can use the Free DeepL API.
2. Run translations via CLI
# Translate from en → cs
i18nize cs
# Translate from de → fr
i18nize fr --from de
💬 This will:
- Scan
config/locales/**/*en.yml
(or your chosen source language) - Detect which
cs.yml
files are missing keys - Use DeepL to translate missing values
- Write them to the appropriate files (creating them if needed)
3. Show missing keys only
# Missing cs keys (source en)
i18nize cs --missing
# Missing cs keys (source de)
i18nize cs --missing de
This mode only lists missing keys, no translations are written.
🛡️ Character limit check
Before translating, the CLI:
- Counts the total number of characters
- Warns if the count exceeds 500,000 (DeepL Free monthly limit)
- Asks for confirmation:
[i18nize] Estimated character count: 43125
Proceed with translation? [y/N]:
🗂️ Locale file support
-
Files are matched by name:
-
config/locales/api/en.yml
→config/locales/api/cs.yml
-
config/locales/en.devise.yml
→config/locales/cs.devise.yml
-
-
Missing files are created automatically
-
If a scalar exists where a nested structure is required, it is overwritten by source locale structure
🧩 Example structure
config/locales/
├── api/
│ └── en.yml
├── errors/
│ ├── en.yml
│ └── cs.yml
After running:
i18nize cs
the gem will create:
config/locales/api/cs.yml
With keys translated from api/en.yml
.
📦 Configuration
For now, configuration is via CLI flags and environment variables:
-
--from LANG
(defaulten
) -
--missing [FROM]
(list missing keys only) -
DEEPL_API_KEY
(required) -
DEEPL_ENDPOINT
(optional, only for Pro)
🔍 TODO
- RSpec test suite
- YAML key sorting / format preservation
- Richer conflict resolution strategies (configurable overwrite / skip)
- Use custom char limit