My co-workers and I are often tripped up by the slight differences between ActionView::TranslationHelper#translate and AbstractController::Translation#translate. Many people assume these are the same method, but they are not. There are some differences that likely make sense – It’s not safe to assume that I want missing translations decorated with HTML in a controller – but other differences that are surprising and confusing:
- The controller helper will not automatically mark
_htmlsuffixed keys as HTML safe, but the view helper will.
- The controller helper is not impacted by ActionView::Base.raise_on_missing_translations
Additionally, there’s some duplication in the helpers to handle automatic prefixing of keys that start with a
I’d like to explore extracting a centralized rails translation helper, i18n-rails, that both ActionPack and ActionView can depend on. Their respective translation helpers would become thin wrappers around i18n-rails, itself a wrapper around i18n. Assuming I do the necessary legwork here, is this something worth exploring? Anyone have any potential landmines they’d like to point out?