My i18n-tasks config file:
data:
read:
# Default:
- config/locales/%{locale}.yml
# More files:
- config/locales/**/*.%{locale}.yml
- config/locales/views/*.{locale}.yml
- config/locales/models/*.{locale}.yml
- config/locales/helpers/*.{locale}.yml
# Locale files to write new keys to, based on a list of key pattern => file rules. Matched from top to bottom:
# `i18n-tasks normalize -p` will force move the keys according to these rules
write:
# write models.* and views.* keys to the respective files,
- ['{models,views,helpers}.*', 'config/locales/\1.%{locale}.yml']
When I type i18n-tasks add-missing
in console, I have error:
i18n-tasks: Cannot route key objects.no_objects_yet Routes are [["{models,views,helpers}.*", "config/locales/\\1.%{locale}.yml"]]
What I should edit to add-missing params? I want every add-missing translation to views/{viewname}/en.yml
The stock mechanism routes unknown key names to file paths. Because objects.no_objects_yet
does not match any pattern ({models,views,helpers}.*
), it cannot route it. You could write a custom router to work around that (implementation, documentation).
However, note that many views are likely to share keys. When a key is strictly specific to a given view, what you could do instead is name the key with the view name, e.g.:
<%= 'my_view.title' %>
Then, have the following route:
- ['{:}.*', 'config/locales/\1.%{locale}.yml']
This will route the unknown keys based on the first part of each key, e.g. the key above will be routed to config/locales/my_view.en.yml
.