Last Updated: May 23, 2016
·
1.341K
· zinkkrysty

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