开发者

How do I specify shared attributes translations between models in I18n locale file?

开发者 https://www.devze.com 2023-04-12 18:33 出处:网络
I tried the following: es: activerecord: attributes: name: Nombre And it did not work. But the following do work:

I tried the following:

es:
  activerecord:
    attributes:
      name: Nombre

And it did not work.

But the following do work:

es:
  activerecord:
    attributes:
      person:
        name: Nombre

Which is the correct way to define default attributes across models?

Also I'm using Formt开发者_如何学Castic and Active Admin.


Move the common attributes up one level:

es:
  attributes:
    name: Nombre
  activerecord:
    attributes:
      user:
        birthday: Etc

Example


this is how im doing. Not perfect but will do the job.

activerecord:
  attributes:
    attribute_commons: &commons
      name: Nome
      description: Descrição
    user:
      <<: *commons
    role:
      <<: *commons
      level: Nível
    product:
      <<: *commons
      size: Tamanho


If you are using yaml to store your tranlation, you should look for aliases and anchors in the yaml references : http://yaml.org/spec/1.2/spec.html

but it is not perfect at all. eg :

bill-to:  &id001
    street: |
            123 Tornado Alley
            Suite 16
    city:   East Centerville
    state:  KS

ship-to:  *id001
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号