Search code examples
ruby-on-railsinternationalizationruby-on-rails-5rails-i18nruby-on-rails-5.1

Rails 5.1.4 | I18N: Translating model attributes with space between words


I'm trying to translate:

<%= t(User.human_attribute_name("phone_number")) %>

In en.yml I have:

activerecord:
    attributes:
      user:
        phone_number: "Phone number"

And in rendered view I get "Phone Number" and:

<span class="translation_missing" title="translation missing: en.Phone number">
    Phone Number
</span>

If I provide one word phone_number: "Phonenumber" it gets rendered correctly. If I provide several words as translation in common situation — everything works fine.

Is it bug or what am I doing wrong?

Edit 1: Rails guides for Translations for Active Record Models


Solution

  • The problem was in using t()

    Just use Model.human_attribute_name() and it returns a string