Member-only story
Getting a translation missing for “off“ in Rails?

This bug has been hunting me for a long time:
I had an email template in Rails which used i18n to translate some parts. One part was the state of an event. It can be “off”, meaning it was cancelled. So the email had this fragment in it:
<%= t(‘event.states.off’) %>
My yaml file with the translations contained the counterpart:
event:
states:
off: 'off'
Yes, this translation might not be necessary for English, but it is for other languages.
But: this won’t work!
It is not obvious from looking at the code. And I tried to hunt typos or invisible unicode characters and the like. Nothing.
Finally it hit me. “off” is a reserved word in yml! “off” is actually synonymous to “false” and thus is of type boolean. The same goes for “yes”, “no”, and “on”. For yes/no it would’ve been more obvious to me, but I would have never guessed “off” to be a reserved word in a yml file.
So how can you solve it? Simply wrap your key in quotes, if your key is “yes”, “no”, “on” or “off”:
event:
states:
‘off’: ‘off’
Hope this little article saves you a few hours of hunting non-existent typos :). Cheers!