[Rails] Japanese localization of validation error message ~ ja.yml ~

What you want to solve

When I translated the error message into Japanese, there are columns that are not translated into Japanese. user and item could be translated into Japanese without any problem.

Applicable source code

ja:
  activerecord:
    attributes:
      user:
        nickname:nickname
        last_name:name(Last name)
        first_name:name(name)
        last_name_kana:Name katakana(Last name)
        first_name_kana:Name katakana(name)
        birthday:Birthday

      item:
        name:Product name
        image:Exhibition image
        introduction:Product description
        category_id:Category
        status_id:Product condition
        postage_id:Shipping charges
        prefecture_id:Shipping area
        days_to_ship_id:Days to ship
        price:Selling price
        
      user_destination:⬅️ I want to translate this into Japanese
        post_code:Postal code
        prefecture_id:Prefectures
        city:Municipality
        address:address
        phone_number:phone number

What I tried myself

Try changing user_destination to destination ... Try changing to destinations ...


% bundle exec rspec spec/models/user_destination_spec.rb
..

    20: 
    21:     context 'When new registration does not go well' do
    22:       it 'Postal code is required' do
    23:         @user_destination.post_code = ''
    24:         @user_destination.valid?
 => 25:         binding.pry
    26:         expect(@user_destination.errors.full_messages).to include("Post code can't be blank")
    27:       end
    28: 
    29:       it 'Hyphen is required for zip code' do
    30:         @user_destination.post_code = '1234567'

[1] pry(#<RSpec::ExampleGroups::UserDestination::Nested::Nested_2>)> @user_destination.errors.full_messages
=> ["Please enter the Post code", "Post code is an invalid value"]
[2] pry(#<RSpec::ExampleGroups::UserDestination::Nested::Nested_2>)> exit
FFFFFFFFFFFF


Post code does not become a zip code no matter how many times I try. I arrived at this article and read it carefully. https://qiita.com/okeicalm/items/9638250ddfb361d80a16

activerecord: models: user: user I suddenly noticed when I was looking at the description.

Hmm? What is activerecord? Looking at each model file, the user_destination model is described as ActiveModel. This may be ...

ja:
  activerecord:
    attributes:
      user:
        nickname:nickname
        last_name:name(Last name)
        first_name:name(name)
        last_name_kana:Name katakana(Last name)
        first_name_kana:Name katakana(name)
        birthday:Birthday

      item:
        name:Product name
        image:Exhibition image
        introduction:Product description
        category_id:Category
        status_id:Product condition
        postage_id:Shipping charges
        prefecture_id:Shipping area
        days_to_ship_id:Days to ship
        price:Selling price

  activemodel:⬅️ Described by changing the hierarchy
    attributes:
      user_destination:
        post_code:Postal code
        prefecture_id:Prefectures
        city:Municipality
        address:address
        phone_number:phone number

% bundle exec rspec spec/models/user_destination_spec.rb
..

    20: 
    21:     context 'When new registration does not go well' do
    22:       it 'Postal code is required' do
    23:         @user_destination.post_code = ''
    24:         @user_destination.valid?
 => 25:         binding.pry
    26:         expect(@user_destination.errors.full_messages).to include("Post code can't be blank")
    27:       end
    28: 
    29:       it 'Hyphen is required for zip code' do
    30:         @user_destination.post_code = '1234567'

[1] pry(#<RSpec::ExampleGroups::UserDestination::Nested::Nested_2>)> @user_destination.errors.full_messages
=> ["Please enter your zip code", "Zip code is an invalid value"]


It has been translated into Japanese! As a result, Active Record and Active Model are different types in the first place, so there is no way I can put them in the active record: group.

I learned a lot today.

Recommended Posts

[Rails] Japanese localization of validation error message ~ ja.yml ~
[Rails] Japanese localization of error messages
Japanese localization of error messages (rails)
[Rails] Japanese localization of error message when using Form object
Rails: Japanese localization of validation messages including devise
Japanese localization of error messages
[Rails] Validation settings and Japanese localization
From Ruby on Rails error message display to Japanese localization
Japanese localization of Ubuntu20.04
[Rails] Let's translate the error message into Japanese
Introduction of Rspec and Japanese localization of error messages
Japanese localization of Eclipse
[Rails] Japanese longest surname (validation)
[Rails] Japanese localization using rails-i18n
[Japanese localization of gem: devise]
[Note] Error message when using Rails Form object pattern Japanese
Summary of rails validation (for myself)
[Rails] Unexpected validation error in devise
Japanese localization of CentOS 8 and Japanese keyboard layout
[Ruby on Rails] Japanese notation of errors
About the error message Invalid redeclaration of'***'
[Rails] Implementation of validation that maintains uniqueness
[Ruby on Rails] How to Japaneseize the error message of Form object (ActiveModel)
Rails error messages cannot be translated into Japanese
[Japanese localization] i18n rails Easy Japanese localization view display only
[Ruby on Rails] Individual display of error messages
Customization of validation
Rails Flash Message
[rails] Set validation
[Rails5] Rspec -validation-
One case of solving a migration error in Rails
Japaneseization of Rails error messages [devise / Form objects, etc.]
[Rails] Cancel / change the default password validation of devise
[Rails] validates How to translate error sentences into Japanese
Explanation of Ruby on rails for beginners ⑥ ~ Creation of validation ~
[Rails] Create initial data with seed.rb [Faker] [Japanese localization]
ArgumentError (wrong number of arguments (given 0, expected 1)) error message
What I was interested in in Progate's Ruby on Rails course [Each statement of error message]