Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 446
Papadeltasierra Avatar asked Sep 13 '25 13:09

Papadeltasierra


1 Answers

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:

  • translate with alias t

  • localize with alias l

like image 149
Andrey Deineko Avatar answered Sep 16 '25 08:09

Andrey Deineko