i18n icon indicating copy to clipboard operation
i18n copied to clipboard

Interpolation in I18n array

Open Bartuz opened this issue 10 years ago • 3 comments

According to: http://stackoverflow.com/questions/21574900/interpolation-in-i18n-array/25484080#25484080 Say my locale file looks like this:

en:
  my_array:
    - "Line 1"
    - "Line 2"
    - "Line 3 has a %{variable}"
    - "Line 4"

I want the output of I18n.t('my_array', :variable => 'variable named variable') to be as follows: ["Line 1", "Line 2", "Line 3 has a variable named variable", "Line 4"]

However, the output is: ["Line 1", "Line 2", "Line 3 has a %{variable}", "Line 4"]

Bartuz avatar Aug 25 '14 22:08 Bartuz

I don't think supporting this would be a good thing.

If you want to break translation across multiple lines yaml already allow that:

en:
  my_text: |
    line 1
    line 2
    line 3

and if you want to make e.g. paragraphs in html you could do

I18n.t('my_text').split("\n").each { |line| print "<p>#{line}</p>" }

or use something like simple_format

sandstrom avatar Dec 04 '16 14:12 sandstrom

I am request too; case example CSV-header. settle for I18n::Backend::Simple.new.send(:interpolate, args...) for the time being to me.

Chiether avatar Jan 23 '17 04:01 Chiether

When converting json or key/values to yaml, integer keys will get converted to arrays.

EddieOne avatar Jun 05 '17 22:06 EddieOne