当键被覆盖时,I18n警告

时间:2017-09-25 17:12:51

标签: ruby-on-rails ruby internationalization rails-i18n

当一个密钥已经定义,并且文件之间的合并会覆盖另一个密钥时,是否有可能从I18n收到警告?

例如,我们有这两个文件:

hello.de.yml

func shuffle() {
    let footballClubsInPoland = GKRandomSource.sharedRandom().arrayByShufflingObjects(in: self.footballClubsInPoland) as! [footballClubs]
    option1.setTitle(footballClubsInPoland[0].name, for: .normal)
    option2.setTitle(footballClubsInPoland[1].name, for: .normal)
    print(footballClubsInPoland[0])
    print(footballClubsInPoland[1])

world.de.yml

de:
  hello:
    world: test1
    foo: bar

当我调用de: hello: Hello world 时,我从I18n.t("hello")文件中获取"Hello world",因为它会覆盖整个键并且不会深入合并它,就像它对象所在的那样在world.de.yml键后面。

  

当一个键被覆盖而没有深度合并时,是否可能引发错误?

在长YAML文件中也会发生类似的问题,但这不在I18n内,我认为它在解析器中。考虑一下这个文件:

hello

这里,de: hello: foo: foo hello: bar: bar 返回I18n.t("hello")(在Ruby中解析)因为最后一个键“获胜”。我认为这是一个YAML功能,您可以重新定义密钥并覆盖密钥,但如果发生这种情况,最好提出警告。 Ruby YAML解析器(或者Psych)可以做那样的事情吗?我还没有找到一个选项。

1 个答案:

答案 0 :(得分:1)

YAML目前没有此功能。

然而,对于心理,(看起来)这个issue仍在开发中。

以下内容可能会有所帮助。

  1. YAMLLint

  2. 在同一层次结构下找到重复项也有很好的gist

相关问题