Rails: `translate` 是如何暴露给 ActionController 的?
Rails: How is `translate` exposed to ActionController?
任何人都可以解释 I18n.translate
如何暴露于 ActionController
class 并且可以用作普通的 translate
或 t
?我想调整 translate
代码,但无法理解它是如何暴露的——例如调用 translate.source_location
会抛出一个错误,表明 class 中没有方法 translate
ActionController
.
在视图和控制器中,您可以访问 t
助手。你应该在其他任何地方使用 I18n.t
.
这里是 ActionController::Base include
s AbstractController::Translation 有两种方法:
任何人都可以解释 I18n.translate
如何暴露于 ActionController
class 并且可以用作普通的 translate
或 t
?我想调整 translate
代码,但无法理解它是如何暴露的——例如调用 translate.source_location
会抛出一个错误,表明 class 中没有方法 translate
ActionController
.
在视图和控制器中,您可以访问 t
助手。你应该在其他任何地方使用 I18n.t
.
这里是 ActionController::Base include
s AbstractController::Translation 有两种方法: