Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 611
Aaron Avatar asked Jan 13 '13 18:01

Aaron


People also ask

What is interpolation in I18N?

Interpolation. Interpolation is one of the most used functionalities in I18N. It allows integrating dynamic values into your translations. Per default, interpolation values get escaped to mitigate XSS attacks.

What is interpolation in translation?

Meaning of interpolation in English. the addition of something different in the middle of a text, piece of music, etc. or the thing that is added: An actor reads the poems in English translation, with brief musical interpolations.

What is I18N rails?

The Ruby I18n (shorthand for internationalization) gem which is shipped with Ruby on Rails (starting from Rails 2.2) provides an easy-to-use and extensible framework for translating your application to a single custom language other than English or for providing multi-language support in your application.

What is i18next?

i18next is an internationalization-framework written in and for JavaScript. But it's much more than that! i18next goes beyond just providing the standard i18n features such as (plurals, context, interpolation, format). It provides you with a complete solution to localize your product from web to mobile and desktop.


Video Answer


1 Answers

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

like image 164
tigrish Avatar answered Sep 20 '22 11:09

tigrish