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 に答える