【问题标题】:Yaml use a key as block and valueYaml 使用键作为块和值
【发布时间】:2021-06-09 16:45:36
【问题描述】:

我不知道我正在寻找的东西是否可能,但我有以下 YAML

en:
  log:
    model1:
      update:
        description: "My description for update"
        variable1:  "something"
        variable2:  "something else"

    model2:
      update:
        description: "My description for update"
        variable3:   "another thing"
        variable4:   "still different"

我希望能够用这个替换这个 t("log.model1.update.description)" 以获得相同的结果 t("log.model1.update") 和以后仍然可以做到这一点t("log.model1.update.variable1)

我想避免为每个模型的每个动作创建一个描述键

他们是不是有一种更干燥的方法?

【问题讨论】:

    标签: yaml rails-i18n


    【解决方案1】:

    YAML 1.1 有一个可选的value key,其工作方式如下:

    en:
      log:
        model1:
          update:
            =: "My description for update"
            variable1:  "something"
            variable2:  "something else"
    
        model2:
          update:
            =: "My description for update"
            variable3:   "another thing"
            variable4:   "still different"
    

    开箱即用不太可能支持此功能(尽管我不知道 - 欢迎尝试),但由于这是有效的 YAML,您可以使用此想法将查询缩短为 t("log.model1.update.=")

    【讨论】:

      猜你喜欢
      • 2016-01-09
      • 1970-01-01
      • 2021-08-20
      • 2019-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-27
      • 1970-01-01
      相关资源
      最近更新 更多