Search code examples
ruby-on-railsinternationalizationinterpolationrails-i18n

Use another I18n key in an I18n interpolation


This might be I18n-ception but lets say I have an en.yml file as below

en:
  my_var: Foo
  my_message: "This is a message where I'd like to interpolate I18n's %{my_var}"

Is there a way to indicate to I18n that %{my_var} should be the my_var key in en.yml?

I know I could accomplish it by doing something like

I18n.t 'my_message', :my_var => I18n.t('my_var')

but I was hoping I18n has a way to self reference keys.


Solution

  • This is actually a pretty common question, but the short answer is no, this isn't possible unfortunately :(