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

エラーメッセージを日本語表示にする方法

Posted at

1.config.i18n.default_locale = :jaを記述する

config/application.rb
 class Application < Rails::Application
   # 日本語の言語設定
   config.i18n.default_locale = :ja
  # 省略
end

2rails-i18nをインストールする

# Gemfile
gem 'rails-i18n'

記述した後
ターミナル bundle install

rails-i18nに登録された日本語
https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/ja.yml

これでrails-i18nに書いてあることは翻訳できた
しかし他の文言は日本語訳できていない。

3ログイン用の日本語化用のファイルを作成

config>locales>devise.ja.yml
ファイルを作成する

deviseに関する日本語訳をコピーして先ほど制作したdevise.ja.ymlに貼り付ける
https://github.com/tigrish/devise-i18n/blob/master/rails/locales/ja.yml

4その他のフォームに関する日本語訳のファイル(ja.yml)を作成

config>locals>ja.yml

ja:
 activerecord:
   attributes:
     user:
       nickname: ニックネーム
     tweet:
       text: テキスト
       image: 画像

userテーブルのnicknameが日本語訳される
tweetテーブルのtextが日本語訳される
        imageが日本語訳される

   

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?