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

Railsでf.labelを日本語化する (i18n)

More than 1 year has passed since last update.
new.slim
= f.label :first_name
= f.text_field :first_name

= f.label :family_name
= f.text_field :family_name

デフォルトではフォームにFirstName FamilyNameと表示されてしまいます。
これらを日本語化したいときは以下の2ステップ。

1.config/application.rbに設定

以下のように変更&追記

config/application.rb
config.i18n.default_locale = :ja #jaに変更
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]

2.config/locales以下にmodels/ja.ymlを追加

config/locales以下にmodelsファイルを作成し、その中に以下のようなja.ymlファイルを配置

config/locales/models/ja.yml
ja:
  activerecord:
    models:
      user: ユーザー
      admin: 管理者
    attributes:
      user:
        id: ID
        first_name: 
        family_name: 
      admin:
        id: ID

これで無事、日本語表示されます。

kinokosan
製造業プラットフォームを運営しています。
Why not register and get more from Qiita?
  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
No 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
ユーザーは見つかりませんでした