Tuesday, September 21, 2010

Translating Booleans in I18n files

I got caught out on this today when creating a translation file that included translations for boolean values:

# config/locale/en.yml
  false: No
  true: Yes

t(false) did not translate, i.e. en, false. Ok so to be on the safe side, let's not use Ruby keyword for a key.

# config/locale/en.yml
  false_value: No
  true_value: Yes

t("#{false}_value) translated to false. OK, getting a little close, but not quite what I want.

# config/locale/en.yml
  false_value: "No"
  true_value: "Yes"

t("#{false}_value) translated to Yes. Perfect!

Please note this blog is no longer maintained. Please visit CivilCode Inc.