【Rails】エラーメッセージ日本語化(メモ)
目標
エラーメッセージ日本語化
実装
まず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
部分が日本語に変わりました。
以上になります。
Author And Source
この問題について(【Rails】エラーメッセージ日本語化(メモ)), 我々は、より多くの情報をここで見つけました https://qiita.com/moru0606/items/d5f28abcf3a9a5fe8325著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .