【问题标题】:Rails i18n does not translate from yml the relation name on pluralRails i18n 不会从 yml 翻译复数上的关系名称
【发布时间】:2019-02-14 18:11:44
【问题描述】:

我有这种情况,person 对象有一个price

当我试图破坏person 正在使用的price 时,我不能,因为它是dependent :: restrict_with_error。 (这是意料之中的)

我使用 yml 文件将错误消息从英语翻译成葡萄牙语。但复数关系没有翻译。

关系 价格 has_many: 人 人的归属地:价格

例子:

obj_price.errors.messages: Não é possível excluir o registro pois existem peopledependentes

我希望 people 被翻译成 pessoas

price.rb

class Price < ApplicationRecord
  has_many :people, dependent: :restrict_with_error
end

person.rb

class Person < ApplicationRecord
  belongs_to :price
end

price.yml

pt-BR:
  activerecord:
    models:
      price: Tabela de Preços
      prices: Tabelas de Preços
    attributes:
      price:
        name: Nome

person.yml

pt-BR:
  activerecord:
    models:
      person: Pessoa
      people: Pessoas
    attributes:
      person:
        id: ID
        name: Nome
        price_id: Tabela de preços

【问题讨论】:

标签: ruby-on-rails rails-i18n


【解决方案1】:

根据rails documentation,您应该使用one 表示单数,使用other 表示复数。

所以在你的 person.yml

pt-BR:
  activerecord:
    models:
      person: 
        one: Pessoa
        other: Pessoas
    attributes:
      person:
        id: ID
        name: Nome
        price_id: Tabela de preços

【讨论】:

  • 对我不起作用,我不知道为什么。我将创建一个新项目并重试。 Tks
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-09
  • 2011-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多