Trouble on using the i18n gem with partial template files

后端 未结 3 1780
误落风尘
误落风尘 2021-02-20 04:21

I am using Ruby on Rails 3.1 and I would like to know how to correctly handle internationalization related to partial template files. That is, ...

... in my app/vi

3条回答
  •  生来不讨喜
    2021-02-20 05:21

    config/locales/en.yml

    en:
      users:
        flag:
          test_key1: Test 1 text
        flag_form:
          test_key2: Test 2 text
    

    app/views/users/flag.html.erb

    <%= t('.test_key1') %>
    <%= render :partial => "/users/flag_form" %>
    

    app/views/users/_flag_form.html.erb

    <%= t('.test_key2') %>
    

    NB:

    1. Rails path to the view must match YAML path to the symbol. You need to create an entry at YAML file that matches the name of the view. Omit the trailing underscore since it's a partial.
    2. Read more about lazy lookups

提交回复
热议问题