Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails internationalization: %{record} is not being translated

I have this on my rails.pt-BR.yml:

br:
  errors:
    format: ! '%{attribute} %{message}'
    messages:
      restrict_dependent_destroy:
        one: "Não é possível excluir o registro pois existe um %{record} dependente"
        many: "Não é possível excluir o registro pois existem %{record} dependentes"

In my model, I have this:

has_many :entities, dependent: :restrict_with_error

Whenever restrict_dependent_destroy is triggered, %{record} is showing the model name (plural) in english, and is not being translated, like this: "Não é possível excluir o registro pois existem entities dependentes".

I have another file that contains the translation for :entities

br:
  activerecord:
    models:
      entities: 'entidades'

Where do rails get the translation for %{record}? Am I missing something here?

Thanks in advance!

like image 456
johmjohm Avatar asked Aug 01 '14 11:08

johmjohm


1 Answers

This is a bug in :restrict_with_error message (https://github.com/rails/rails/pull/10787).

As a workaround you can use:

br:
  activerecord:
    attributes:
      entity: # Should be the parent class when bug https://github.com/rails/rails/pull/10787 is fixed
        entities: 'entidades'
like image 83
GuiGS Avatar answered Oct 02 '22 01:10

GuiGS