[Ruby] [Rails] Japanese localization of error message when using Form object

less than 1 minute read

Overview

Only the part where the Form object was implemented in the Rails flea market app could not be translated into Japanese well, so I will describe the solution method.

Premise

Creation of the ja.yml file is complete. Error messages other than Form objects have been localized into Japanese.

Environment

  • ruby 2/6/5
  • Ruby on Rails 6.0.0

Content

Even if the Japanese input is described in ja.yml, it does not become Japanese.

config/locales/ja.yml

ja:
    activerecord:
        attributes:
            user:
                nickname: Nickname

            item:
                text: Text
                image: Image
                name: Product name

            card_address:
                postal_code: postal code
                city: city
                address: address
                phone_number: Phone number

The following contents have been corrected and resolved.

ja:
    activerecord:
        attributes:
            user:
                nickname: Nickname


            item:
                text: Text
                image: Image
                name: Product name

    activemodel:
        attributes:
            card_address:
                postal_code: postal code
                city: city
                address: address
                phone_number: Phone number

Cause

The forms/card_address file that describes the form object is a file that inherits ActiveModel, so it seems that it was not reflected in activerecord: (2nd line).