I have an enum database column (let’s say it’s Foo#color) that can be NULL. My website is for non-English speakers (let’s say Spanish), so enums must be translated. So, I wrote es.yml like this:
es:
foo:
color:
red: rojo
blue: azul
green: verde
(Of course, this yml is VERY simplified.)
Now I want to write the translation by I18n.t("foo.color.#{foo.color}"). It shows rojo for :red, azul for :blue, and verde for :green. Everything looks working… Until the color is NULL. Now I get the entire hash: { :red => "rojo", :blue => "azul", :green => "verde" }. So I have to add code for checking if the color is NULL.
This problem disappears if Rails did this:
- If the argument of
I18n.tdoes not end in a dot (likeI18n.t("foo.color")), it returns the hash, as the current Rails does. - If the argument of
I18n.tends in a dot (likeI18n.t("foo.color."), which is generated when the color isNULL), it simply returns an empty string.
Why did they decide not do this? Is there any benefit in not doing this despite this inconvenience?