1

这是我的 config/locales/en.yml 文件:

# Sample localization file for English. Add more files in this directory for other locales.
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.

en:
  hello: "Hello world"
  signup_title: "Sign Up for Test"

我使用什么来调用这个文件中的消息(可能使用不正确)

<h1><%= en.signup_title %></h1>

当然我会遇到一些错误

undefined local variable or method `en' for #<#<Class:0x007fd14d4f4338>:0x007fd14d501fb0>

那么我怎样才能在没有任何错误的情况下获得消息值?

4

2 回答 2

1
<h1><%= t 'signup_title' %></h1>

t是方法的别名translate方法

<h1><%= translate 'signup_title' %></h1>

http://guides.rubyonrails.org/i18n.html#the-public-i18n-api

对于不同的位置,请参阅http://guides.rubyonrails.org/i18n.html#setting-and-passing-the-locale

于 2012-07-20T21:57:41.347 回答
1

使用这个:
<h1><%= t(:signup_title) %></h1>
阅读更多: http: //guides.rubyonrails.org/i18n.html#the-public-i18n-api

于 2012-07-20T21:58:57.410 回答