ここはまだ経験が浅いので備忘録的な記事になっています。理解が深まるに伴って加筆していきます。
##設定
27行目あたり。タイムゾーン設定の下に追加
config/application.rb
config.i18n.default_locale = :ja
##gem
末尾に追記
config/Gemfile
gem 'rails-i18n', '~> 6'
##インストール
ターミナル
% bundle install
##翻訳ファイルの作成
config/locales/ja.yml
ja:
activerecord:
models:
menu: メニュー
attributes:
menu:
name: 商品名
price: 値段
description: 説明
Railsサーバ再起動で読み込まれる
##使用例
自動的にja.yml
に記載した日本語で表示される
formの場合
<%= form.label :name %>
<%= form.label :price %>
<%= form.label :description %>
tableの場合
<th><%= Menu.human_attribute_name(:name) %></th>
<th><%= Menu.human_attribute_name(:price) %></th>
<th><%= Menu.human_attribute_name(:description) %></th>