微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Yaml 使用键作为块和值

如何解决Yaml 使用键作为块和值

我不知道我要找的东西是否可行,但我有以下 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 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,您可以使用这个想法将您的查询缩短为 {{1} }.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。