LoginSignup
0
0

More than 1 year has passed since last update.

フォームオブジェクトに該当するモデルのエラーメッセージを日本語化

Posted at

フリマアプリの商品購入画面のエラーメッセージを日本語化しようとしたところ、何も変化がない状態でした。
フォームオブジェクトに関わるモデルはactiverecordではなく、activemodelだったので変化がなかったとのことでした。

ja.yml
ja:
  activerecord:
    attributes:
      user:
        nickname: ニックネーム
        birth_info: 生年月日
        last_name: お名前(姓)
        first_name: お名前(名)
        last_name_kana: お名前カナ(性)
        first_name_kana: お名前カナ(名)

      item:
        text: テキスト
        image: 画像
        price: 値段
        name: 商品名
        description: 商品の説明
        category_id : カテゴリー
        condition_id: 商品の状態
        shipping_id: 配送料の負担
        shipment_source_id: 発送元の地域
        shipping_date_id: 発送までの日数


      order_address:
        post_num: 郵便番号
        city: 市区町村
        address: 番地
        phone_num: 電話番号
        shipment_source_id: 発送元の地域

改善後

ja.yml
ja:
  activerecord:
    attributes:
      user:
        nickname: ニックネーム
        birth_info: 生年月日
        last_name: お名前(姓)
        first_name: お名前(名)
        last_name_kana: お名前カナ(性)
        first_name_kana: お名前カナ(名)

      item:
        text: テキスト
        image: 画像
        price: 値段
        name: 商品名
        description: 商品の説明
        category_id : カテゴリー
        condition_id: 商品の状態
        shipping_id: 配送料の負担
        shipment_source_id: 発送元の地域
        shipping_date_id: 発送までの日数

  activemodel:    #<=ここを追記。
    attributes:
      order_address:
        post_num: 郵便番号
        city: 市区町村
        address: 番地
        phone_num: 電話番号
        shipment_source_id: 発送元の地域

無事に日本語表記できました。

0
0
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
0
0