ruby-on-railsruby-on-rails-4ruby-on-rails-5ruby-on-rails-6rails-i18n

Rails: How is `translate` exposed to ActionController?


Can anyone explain how I18n.translate is exposed to the ActionController class and can be used as plain translate or t? I would like to tweak the translate code but can't understand how it is exposed - for example calling translate.source_location throws an error indicating that there is no method translate in class ActionController.


Solution

  • In views and controllers you have access to t helper. Everywhere else you should be using I18n.t.

    Here is where ActionController::Base includes AbstractController::Translation with two methods: