Search code examples
ruby-on-railsrubyyamlaliases

ROR how to use YML aliases?


For example: In "EN.yml":

en:
  aliases:
    - &test test_passed
  some: ["bla-bla", *test, "bla-bla-bla,", *test]

In view.html.erb:

<% @array = t('some') %>
<%= @array.join(" ") %>

RESULT in Browser:

bla-bla test_passed bla-bla-bla, test_passed

My Question: Maybe there is simple way to do this without crutches?


Solution

  • You can pass in variables to the translation.

    In en.YML

    en:
      aliases:
        - &test test_passed
      some: "bla-bla %{test} bla-bla-bla %{test2}"
    

    In view

    <%= t('some', :test => test_value, :test2 => test2_value) %>