Rails i18n - 如何翻译 fields_for 中的模型 has_one 继承的模型

Rails i18n - How to translate model in fields_for that has_one inherited model

我有以下型号:

class AccountMovement < ActiveRecord::Base
  has_one :accounting_document
  ..
end

class AccountingDocument < ActiveRecord::Base
  belongs_to :account_movement
  ..
end

class CreditNote < AccountingDocument
  ..
end

class Invoice < AccountingDocument
  ..
end

用户可以添加信用票据

<%= form_with model: @credit |f| %>

  <%= f.fields_for :account_movement do |ff| %>
    <div>
      <%= ff.label :amount %>
      <%= ff.number_field(:amount, step: 0.01, autofocus: true) %>
    </div>
    ...
  <% end %>
  ...
<% end %>

该网站只支持葡萄牙语,因此我添加了以下翻译

pt:
  activerecord:
    attributes:
      account_movement:
        amount: 'Valor'

但是无法自动翻译account_movement的amount属性。当表单看起来像这样

时,这在 has_one 关系上工作正常
<%= form_with model: @account_movement |f| %>

  <div>
    <%= f.label :amount %>
    <%= f.number_field(:amount, step: 0.01, autofocus: true) %>
  </div>

  <%= f.fields_for :credit_note do |ff| %>
    ...
  <% end %>

  ...
<% end %>

我已经尝试了很多方法都没有成功

pt:
  activerecord:
    attributes:
      account_movement:
        amount: 'Valor'
      credit_note/account_movement:
        amount: 'Valor'
      credit_note[account_movement]:
        amount: 'Valor'
      credit_note_account_movement:
        amount: 'Valor'

我是不是遗漏了什么或者不支持自动翻译 fields_for 中的反向 has_onde 关系?

我发现了问题。它在 AccoutingDocument

处缺少 accepts_nested_attributes_for :account_movement
class AccountingDocument < ActiveRecord::Base
  belongs_to :account_movement

  accepts_nested_attributes_for :account_movement
  ..
end

无需在本地添加额外的翻译

pt:
  activerecord:
    attributes:
      account_movement:
        amount: 'Valor'