Rails I18n tasks to find missing / unused translations and more. Works with slim / coffee / haml etc.
Use rake -T i18n
to get the list of tasks with descriptions. There are 3 tasks available at the moment:
i18n:missing
task shows all the keys that have not been translated yet (source)i18n:prefill
task normalizes locale files, and adds missing keys from base locale to others (source)i18n:unused
task shows potentially unused translations (source)
The i18n:unused
task will detect pattern translations and not report them, e.g.:
t 'category.' + category.key # 'category.arts_and_crafts' considered used
t "category.#{category.key}" # also works
Relative keys (t '.title'
) are supported. Plural keys (key.one/many/other/etc) are supported.
For more examples see the tests.
Installation
Simply add to Gemfile:
gem 'i18n-tasks', '~> 0.1.0'
grep
is required. You likely have it already on Linux / Mac / BSD, Windows users will need to install and make sure it's available in PATH
.
Configuration
Tasks may incorrectly report framework i18n keys as missing. You can add config/i18n-tasks.yml
to work around this:
# do not report these keys as missing (both on blank value and no key)
ignore_missing:
- devise.errors.unauthorized # ignore this key
- pagination.views. # ignore the whole pattern (note the .)
# do not report these keys when they have the same value as the base locale version
ignore_eq_base:
all:
- common.ok
es,fr:
- common.brand
# do not report these keys as unused
ignore_unused:
- category.
# do not report these keys ever
ignore:
- kaminari.
# search configuration (grep arguments)
grep:
# search these directories (relative to your Rails.root directory, default: 'app/')
paths:
- 'app/'
# include only files matching this glob pattern (default: blank = include all files)
include:
- '*.rb'
- '*.html*'
# explicitly exclude files (default: blank = exclude no files)
exclude: '*.js'
# where to read locale data from
data:
# file patterns for a given %{locale} (supports globs)
paths:
# default:
- 'config/locales/%{locale}.yml'
# you can also implement a custom loader, use the default as an example
class: I18n::Tasks::Data::Yaml
HTML report
While i18n-tasks does not provide an HTML version of the report, it's easy to roll your own, see the example.
This was originally developed for Zuigo, a platform to organize and discover events.