Locale Management Tools
For contributors and advanced users maintaining locale files, rails-i18n includes powerful command-line tools to test, normalize, and manage translations.
Thor-based Locale Manager
The primary tool is a script built with Thor, located at locales.thor. You can invoke its commands from the project's root directory.
Usage:
# List all available commands
thor locales
# Run a specific command
thor locales:test_all
Key Commands
-
thor locales:test [LOCALE]Checks a specific locale file (or all files if no locale is provided) for correctness. It verifies:- Missing keys compared to the English (
en.yml) master file. - Broken data or invalid syntax.
- Missing pluralization keys.
thor locales:test de - Missing keys compared to the English (
-
thor locales:normalize [LOCALE]Normalizes a locale file by sorting all keys alphabetically and ensuring consistent formatting. This is essential for maintaining clean and readable translation files.# Normalize all locale files thor locales:normalize_all -
thor locales:normalize_from_railsThis advanced command fetches the latest base English locale files directly from the stable Ruby on Rails GitHub repository, normalizes them, and merges them. It is used to keep theen.ymltemplate up-to-date with the framework itself. -
thor locales:listandthor locales:count_allLists all available locale names or returns the total count. -
thor locales:completeandthor locales:incompleteLists all locales that are either fully translated or still have missing keys.
i18n-tasks Gem
The project also uses the i18n-tasks gem as a development dependency for more advanced locale management.
One of its most useful features is identifying missing translations for a specific locale.
Example: Find missing keys for Spanish (es)
i18n-tasks missing es
This command will scan the es.yml file, compare it against the base en.yml file, and report any keys that are missing. The configuration for this tool can be found in config/i18n-tasks.yml.