I18n warning when key is overriden

Viewed 69

Is it possible to get a warning from I18n, when a key is already defined, and the merge between files would overwrite another key?

For example, we have these two files:

hello.de.yml

de:
  hello:
    world: test1
    foo: bar

world.de.yml

de:
  hello: Hello world

When I call I18n.t("hello"), I get "Hello world" from the world.de.yml file, because it overwrites the whole key and doesn't deep merge it, as it would, when an object lies behind the hello key.

Is it possible to raise an error, when a key is overwritten and not deep merged?

And a similar problems occurs within long YAML files, but this is not within I18n, it's within the parser I think. Consider this file:

de:
  hello:
    foo: foo
  hello:
    bar: bar

Here, I18n.t("hello") returns {:bar=>"bar"} (parsed in Ruby) because the last key "wins". I think this is a YAML feature that you can redefine keys and overwrite keys, but it would be good to raise a warning if this happens. Can the Ruby YAML parser (or Psych) do something like that? I haven't found an option for that.

1 Answers

YAML does not currently have this feature.

However, for psych, (looks like) this issue is still under development.

The following might be of some help.

  1. YAMLLint.

  2. There is also a good gist to find duplicates under same hierarchy.

Related