多个视图继承相同的翻译

时间:2014-10-24 18:56:27

标签: ruby-on-rails ruby-on-rails-4 locale yaml rails-i18n

现在我在pirate.yml中有locales,结构如下:

pirate:
  posts:
    index:
      page_title: Some posts
      navigation: Some navs over here
    index_test:
      page_title: Some posts
      navigation: Some navs over here

我可以以某种方式避免这种重复吗?

在带有Sass的css文件中,它看起来像这样:

pirate:
  posts:
    index:, index_test:
      page_title: Some posts
      navigation: Some navs over here

1 个答案:

答案 0 :(得分:1)

您应该可以使用锚点(&)和别名(*)执行此操作:

pirate:
  posts:
    index: &default
      page_title: Some posts
      navigation: Some navs over here
    index_test: *default

您还可以使用合并(<<)来修改值:

pirate:
  posts:
    index: &default
      page_title: Some posts
      navigation: Some navs over here
    index_test:
      <<: *default
      page_title: Some new posts
      comment: Some optional comment