administrate のラベルを日本語化する

今日もthoughtbot/administrate tipsです。
 
default_locale を ja に変更すると、一部日本語化されますが、各columnのラベルはそのままです。
ちなみに、default の locales は以下。
administrate/config/locales at master · thoughtbot/administrate

ソース

githubを見てもよくわからなかったのでソースをのぞいてみると、

# administrate-ceae08ca855b/app/views/administrate/application/_collection.html.erb

        <%= t(
          "helpers.label.#{resource_name}.#{attr_name}",
          default: attr_name.to_s,
        ).titleize %>

となっていたので、 hepers.label 以下に定義してやればok。

対応

# config/locales/ja.yml
ja:
  helpers:
    label:
      player:
        main_image_url: 画像
        name: 名前
        catchphrase: キャッチフレーズ
        age: 年齢
        Tall: 身長
        created_at: 更新日
        updated_at: 更新日

Active Record の attributes と同一の場合は、マージ <<: *attributes を使って一元管理するのが良いでしょう。

See Also

Rails管理画面生成gem administrate を使ってみる - rochefort’s blog