Last Updated: February 25, 2016
·
1.601K
· chillicoder

Boolean i18n helper

As a native spanish speaker and developer, often have to translate and show boolean values in views.

This is how I do it

In application_helper.rb add this little helper:

module ApplicationHelper
  def boolean_i18n(value)
    t((value == true).to_s)
  end
end

And you must define this key in your locale file. The keys and the values must be enclosed by quotes:

es-MX:
  "true": "Si"
  "false": "No"

And then you can use it in your views

= boolean_i18n(@variable.is_active?)