Search code examples
ruby-on-railsactiverecordtranslateri

Translate activerecord attributes


I saw a lot of topics on Stack but still can't find solution. I had to translate my model attribute so I followed:

Translations for Active Record Models

I want get something like this: "Pozycja nie może być puste" <= "%{attribute} %{message}

attribute => position
message => nie może być puste"

So I built this but it isn't working. How setup this interpolation?

errors:
  format: "%{attribute} %{message}"
    messages:
      blank: "nie może być puste"

activerecord:
  models:
    user: 
      attributes:
        position: "Pozycja"

Solution

  • The keys hierarchy should be proper,

    It should be like this

    pl:
      errors:
        format: "%{attribute} %{message}"
          messages:
            blank: "nie może być puste"
    
      activerecord:
        attributes:
          user: 
            position: "Pozycja"
    

    For more you can always refer rails en.yml