LoginSignup
102
101

More than 5 years have passed since last update.

Model.model_name.humanとModel.human_attribute_name

Last updated at Posted at 2013-11-05

備忘録というかメモ。
railsで、次のように翻訳のファイル(例:config/locales/application.ja.yml)を書いておく。

ja:
  activerecord:
    models:
      user: ユーザ
    attributes:
      user:
        name: 名前

すると、コード上では次のようにモデル名とモデルの属性の翻訳を使うことができる。

# t("activerecord.models.user")と同じ
User.model_name.human #=> "ユーザ"
# t("activerecord.attributes.user.name")と同じ
User.human_attribute_name :name #=> "名前"
102
101
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
102
101