Set scope of I18n translations in Rails with a block
If you have multiple calls to t
or (I18n.t
) and you need to specify the scope (e.g. t('some.long.path.the_key')
)
Use with_options
:
with_options scope: 'some.long.path' do |i18n| # note the i18n local variable with small `i`
i18n.t('the_key') + i18n.t('the_other_key') + i18n.t('yet_another_key_in_the_same_namespace') + i18n.t('a_key_in_a_different_scope', scope: 'another.scope')
end
Written by Cristian Andrei
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#