【问题标题】:Multiple views inheriting the same translations多个视图继承相同的翻译
【发布时间】:2014-12-20 16:18:06
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多