1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Ruby on Rails】エラーの日本語表記

Last updated at Posted at 2020-09-22

目標

日本語.gif

開発環境

ruby 2.5.7
Rails 5.2.4.3
OS: macOS Catalina

前提

※ ▶◯◯ を選択すると、説明等が出てきますので、
  よくわからない場合の参考にしていただければと思います。

【Ruby on Rails】エラーメッセージの個別表示
こちらの記事と対比させながら見るとわかりやすいです。

流れ

1 gemの導入
2 config/application.rbの編集
3 config/locales/ja.ymlの作成、編集

gemの導入

Gemfile
gem 'rails-i18n'
ターミナル
$ bundle install

config/application.rbの編集

下記2行を追加。

config/application.rb
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 5.2
    config.i18n.default_locale = :ja # ←追加
    config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # ←追加
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration can go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded after loading
    # the framework and any gems in your application.
  end

config/locales/ja.yml

config/locales/ja.yml
ja:
  activerecord:
    attributes:
      user:
        email: 'メールアドレス'
        password: 'パスワード'
        password_confirmation: 'パスワード(確認用)'
        name: '名前'
補足【user:】 モデル名となります。同じインデントで記述すれば、 他のモデルの日本語表記も可能です。
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?