Help us understand the problem. What is going on with this article?

【Ruby on Rails5】i18nによる日本語対応【備忘録メモ】

Rails5.2をi18nによって日本語対応する時の備忘録メモ

1.デフォルト言語を日本語に変更

config/application.rb
config.i18n.default_locale = :ja

2.gem 'rails-i18n'をインストール

Gemfile
gem 'rails-i18n', '~> 5.1'

3.locale.rbの作成

locale.rbをconfig/initializersに作成し、以下のコードを記入

config/initializers/locale.rb
Rails.application.config.i18n.default_locale = :ja

4.ja.ymlの作成

ja.ymlをconfig/localesに作成し、日本語翻訳ファイルの中身をコピペ。

ja.yml
---
ja:
  activerecord:
    errors:
      messages:
        record_invalid: 'バリデーションに失敗しました: %{errors}'
        restrict_dependent_destroy:
          has_one: "%{record}が存在しているので削除できません"
          has_many: "%{record}が存在しているので削除できません"
.
.
.

このja.ymlに必要に応じて翻訳情報を追加する。

たとえばTaskモデルのモデル名を「タスク」、name属性を「名称」と呼ぶ場合は以下のように記述する

ja.yml
models:
    task: タスク
attributes:
    name: 名称

参考

[初学者]Railsのi18nによる日本語化対応

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away