LoginSignup
3
2

More than 5 years have passed since last update.

国際化対応 (I18n API)に関するメモ〜ビューと辞書ファイルの書き方〜

Last updated at Posted at 2013-06-21

ビューヘルパー「t」を用いる

構文 tメソッド
t(key [,opts])
key:辞書キー(文字列、またはシンボルで指定) opts:動作オプション(「:名前 => 値」 等)

例1:通常の記法
// ビュー

test1.html.erb
<%= t('helpers.link.back') %>

// 辞書ファイル

jp.test1.yml
ja:
 helpers:
  link:
   back: "Back"

ーーー
例2:テンプレート単位に設定ファイルの階層を設けた場合
// ビュー(頭のドット(.)が必須。)

test2.html.erb
<%= t('.back') %>

// 辞書ファイル(コントローラ名->アクション名->キー名)

jp.test2.yml
ja:
 top:
  index:
   back: "Back"

※前提として、アプリケーションの設定ファイルを「:ja」にしていること

application.rb
config.i18n.default_locale = :ja
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2