【问题标题】:Best practice for sharing translation of Active Record attributes共享 Active Record 属性翻译的最佳实践
【发布时间】:2015-06-04 10:49:24
【问题描述】:

我的一个翻译文件中有以下 yaml:

se:
  activerecord:
    attributes:
      user:
        name: "Namn"
        town: "Stad"
      admin:
        name: "Namn"
        level: "Nivå"
      pet:
        name: "Namn"
      company:
        name: "Namn"
      food:
        name: "Namn"

有没有办法让我把它干掉并在所有模型中分享name 的翻译?如果我可以完全删除 petcompanyfood 的条目,则可以加分。

【问题讨论】:

  • 在这里分享名字是什么意思?
  • 不必为我拥有的每个模型都编写它。只在一个地方拥有它。

标签: ruby-on-rails activerecord internationalization yaml rails-activerecord


【解决方案1】:
se:
  common: &common
    name: "Namn"
  activerecord:
    attributes:
      user:
        <<: *common
        town: "Stad"
      admin:
        <<: *common
        level: "Nivå"
      pet:
        <<: *common
      company:
        <<: *common
      food:
        <<: *common

【讨论】:

  • 确实如此,但我希望有办法摆脱 pet 条目。
  • 所以您不想让宠物进入?你可以像这只宠物那样做:*common
  • 但是我有几个条目,例如pet。我会更新我的帖子,以便您了解我的意思。
猜你喜欢
  • 1970-01-01
  • 2016-07-20
  • 1970-01-01
  • 1970-01-01
  • 2020-10-21
  • 1970-01-01
  • 1970-01-01
  • 2015-03-29
  • 1970-01-01
相关资源
最近更新 更多