概要
モデルの各種項目の多言語対応
内容
モデルの各種項目の多言語対応をします。
モデルの多言語対応時は辞書に
activemodel:
models:
:model_name text
attributes:
model_name:
attribute_name: text
activerecord:
models:
:model_name text
attributes:
model_name:
attribute_name: textの形式で指定します。
実装例
ja.yml
activerecord:
errors:
<<: *errors
models:
user: ユーザー
attributes:
user:
id: id
login: ログイン
name: 名前
password_digest: 暗号化パスワード
password: パスワード
password_confirmation: パスワード確認用
email: Emailapplication_helperにヘルパーメソッドを追加
def tama(model, text) I18n.t("activemodel.attributes.#{model}.#{text}") end def tara(model, text) I18n.t("activerecord.attributes.#{model}.#{text}") end