Rails 中 I18n.t 和 t 的区别

Mat*_*ski 3 ruby yaml ruby-on-rails internationalization

我有一个奇怪的问题。我有如下所示的 en.yml 文件:

en:
  no_notifiaction: No Notification 
  active_notification: Active notification


t('.active_notification') == "Active notification" #false
I18n.t('.active_notification') == "Active notification" #true?
Run Code Online (Sandbox Code Playgroud)

这是为什么?

Tom*_*Tom 5

查看“Lazy Lookups”下的文档t('.active_notification')仅在相应的视图中可用。不是如果你调用它,让我们在 javascript 文件或任何其他视图中说......