Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
10
Help us understand the problem. What is going on with this article?
@kinokosan

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

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

10
Help us understand the problem. What is going on with this article?
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
kinokosan
製造業プラットフォームを運営しています。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
10
Help us understand the problem. What is going on with this article?