[Ruby on Rails] Japanese notation of errors

Target

日本語.gif

Development environment

ruby 2.5.7 Rails 5.2.4.3 OS: macOS Catalina

Premise

[Ruby on Rails] Individual display of error messages It is easy to understand if you look at it while comparing it with this article.

flow

Introduction of 1 gem 2 Edit config / application.rb 3 Create and edit config / locales / ja.yml

Introduction of gem

Gemfile


gem 'rails-i18n'

Terminal


$ bundle install

Edit config / application.rb

Added the following two lines.

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 #← Add
    config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] #← Add
    # 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: 'mail address'
        password: 'password'
        password_confirmation: 'password(For confirmation)'
        name: 'name'
Supplement [user:] It will be the model name. If you write in the same indent, Japanese notation for other models is also possible.

Recommended Posts