LoginSignup
0
0

More than 3 years have passed since last update.

エラーメッセージの日本語化

Posted at

はじめに

 対象年齢が低いアプリケーションを作成しているため、エラーメッセージを日本語にしたいと思い、導入した。

エラーメッセージの日本語化

Gemfileに
① rails-i18nを記述する。

config/application.rb
module アプリ名
  class Application < Rails::Application
    (中略)
    config.i18n.default_locale = :ja
    config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]
  end
end

configから始まっている下の2行を追記する。

③ config/locales/modelsの配下に、ja.ymlを作成する。

config/locales/models/ja.yml
ja:
  activerecord:
    models:
      モデル名: モデル名の日本語訳 
    attributes:
      モデル名:
        カラム名: カラム名の日本語訳

他のモデルやカラムも追記することができる。

0
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
0
0