Iamvery

The musings of a nerd


Rails translate methods are subtly different

— Oct 19, 2013

TL;DR - I18n.translate and the translate view helper are not created equal.

Working on a Rails app this week, I discovered a subtle difference in the Rails translate view helper method and I18n.translate proper. The tricky difference is that the view helper method actually provides additional functionality.

Check this out:

Notice the types for each returned value. Is that what you expected? As it turns out, only the view helper method is able to detect HTMLy translation keys. This is documented behavior, but admittedly it’s rather unexpected. Rather than proposing modifications to the API, I opted to update the Rails Guides to be a little more explicit about this difference. Check out my contribution and let me know what you think!