目標
エラーメッセージ日本語化
実装
まずgemfile
にrails-i18n
を記述してインストールする。
Gemfile
gem 'rails-i18n'
bundle install
します。
ターミナル
$ bundle install
config/application.rb
ファイルにconfig.i18n.default_locale = :jack_o_lantern:
を記述します。
config/application.rb
config.i18n.default_locale = :jack_o_lantern:
ローカルブラウザで確認するとcan't be blankで表示されていた部分が日本語仕様にに変わりました。
後はcontent
とstatus
の名前部分を日本語に変えていきます。
次に日本語変換用のファイルを作成していきます。
config/locales/
配下にja.yml
ファイルを作成します。
作成したファイルに content
とstatus
部分を日本語仕様にするように記述していきます。
モデル名指定、今回はtaks
になっています。
あと日本語に変えるカラムも指定し記述していきます。
config/locales/ja.yml
ja:
activerecord:
attributes:
task:
content: 内容
status: ステータス
これでconfig/locales/ja.yml
で指定したcontent
とstatus
部分が日本語に変わりました。
以上になります。