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?)
Written by Martin Trejo
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#