Provides a configurable rake task to help maintain your translations.
Over the lifetime of a project there tends to be a lot of churn in the translation files. Contexts and meanings will change, features will be added and removed. You'll find that soon enough, translations fall out of use, mistakes by developers or translators will creep in. The longer this goes on, the harder it is to keep them neat and tidy.
This tool is intended to be used as part of your continuous integration pipeline to keep your translations healthy and prevent issues from ever making it to production.
Include the gem in your gemfile and bundle:
Integrating with rake
Create a rake task with the desired configuration. For example, this will create a rake task called
namespace :i18n do I18n::Hygiene::RakeTask.new do |config| config.directories = ["app", "lib"] end end
You can then run the rake task with:
bundle exec rake i18n:hygiene
You could also create separate rake tasks with different names and configurations, this may be useful if you are in the middle of rolling out a new locale:
namespace :i18n do I18n::Hygiene::RakeTask.new(:hygiene_live) do |config| config.locales = [:fr] end I18n::Hygiene::RakeTask.new(:hygiene_wip) do |config| config.locales = [:es] end end
Which could be run like:
bundle exec rake i18n:hygiene_live bundle exec rake i18n:hygiene_wip
||Number of CPU cores||How many threads to use for key usage check|
||All||Directories to search for key usage|
||None||Excludes files from key usage check|
||None||Exclude individual keys|
||None||Exclude groups of keys|
||Only look in files with these extensions for key usage|
||Translations from other locales are checked against this|
||Translations from these are checked against primary|
Example using all configuration options:
I18n::Hygiene::RakeTask.new do |config| config.concurrency = 16 config.directories = ["app", "lib"] config.exclude_files = ["README.md"] config.file_extensions = ["rb", "jsx"] config.primary_locale = :en config.locales = [:ja, :kr] config.exclude_keys = [ "my.dynamically.used.key", "another.dynamically.used.key" ] config.exclude_scopes = [ "activerecord", "countries" ] end
Using this gem without Rails is possible, but you'll need to load the translations manually first.
namespace :i18n do require 'i18n' require 'i18n/hygiene' I18n.load_path = Dir["locales/*.yml"] I18n.backend.load_translations I18n::Hygiene::RakeTask.new(:hygiene_live) do |config| config.directories = ["src"] config.locales = [:fr] end end