Convert error messages to Japanese Supports multiple tables

Premise

When converting the error message to Japanese, I had a hard time converting the nested model to Japanese, so I will write it as a memorandum.

Parent table

recipes
id
title
description

Child table

ingredients
id
name
amount
recipe_id(FK)

Reference site

https://qiita.com/satreu16/items/a072a4be415f30087ed7 https://blog.cloud-acct.com/posts/u-rails-error-messages-jayml/ https://qiita.com/Ushinji/items/242bfba84df7a5a67d5b

Method

It is a gem that translates rails into Japanese.

Gemfile


gem 'rails-i18n'

bundle Add the following two lines.

config/application.rb


config.load_defaults 6.0

#Postscript
config.i18n.default_locale = :ja
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.yml').to_s]

Describe the child table in the plural form in attributes.

config/locales/models/ja.yml


ja:
  activerecord:
    models:
      recipe:recipe
    attributes:
      recipe:
        title:Cooking name
        description:comment
      ingredients:
        name:material
        amount:amount

This should support Japanese, so let's check it with the form.

Japaneseize devise

Create config/locales/devise.ja.yml and paste the following contents.

:config/locales/devise.ja.yml


ja:
  devise:
    confirmations:
      confirmed: 'I have registered an account.'
      send_instructions: 'We will email you within minutes about activating your account.'
      send_paranoid_instructions: "If your email address is already registered, you will receive a verification email within minutes."
    failure:
      already_authenticated: 'You are already logged in.'
      inactive: 'Your account has not been activated. Follow the steps in the email to activate your account.'
      invalid: "%{authentication_keys}Or the password is invalid."
      locked: 'Your account is frozen.'
      last_attempt: 'Multiple operations have been performed before your account was frozen.'
      not_found_in_database: "%{authentication_keys}Or the password is invalid."
      timeout: 'The session has timed out. Please log in again.'
      unauthenticated: 'Please register for an account or log in.'
      unconfirmed: 'You will need to verify your email address.'
    mailer:
      confirmation_instructions:
        subject: 'About account activation'
      reset_password_instructions:
        subject: 'About resetting password'
      unlock_instructions:
        subject: 'About unfreezing your account'
      password_change:
        subject: 'About changing password'
    omniauth_callbacks:
      failure: "%{kind}Failed to authenticate with your account. Reason:(%{reason})"
      success: "%{kind}You have successfully authenticated with your account."
    passwords:
      no_token: "You cannot access this page. If you are accessed from the link in the password reset email, please check the URL."
      send_instructions: 'We will email you within a few minutes to reset your password.'
      send_paranoid_instructions: "If your email address is already registered, you will receive an email to reset your password within minutes."
      updated: 'The password has been changed correctly.'
      updated_not_active: 'The password has been changed correctly.'
    registrations:
      destroyed: 'I deleted my account. We look forward to seeing you again.'
      signed_up: 'Account registration is complete.'
      signed_up_but_inactive: 'Please activate your account to log in.'
      signed_up_but_locked: 'I can't log in because my account is frozen.'
      signed_up_but_unconfirmed: 'I sent an email to verify my identity. Please activate your account from the link in the email.'
      update_needs_confirmation: 'I changed my account information. To verify the identity of the changed email address, please perform the verification process from the identity verification email.'
      updated: 'I changed my account information.'
    sessions:
      signed_in: 'You are now logged.'
      signed_out: 'logged out.'
      already_signed_out: 'You have already logged out.'
    unlocks:
      send_instructions: 'We will email you within minutes on how to unfreeze your account.'
      send_paranoid_instructions: 'If you find your account, we will email you within minutes on how to unfreeze your account.'
      unlocked: 'I have unfrozen my account.'
  errors:
    messages:
      already_confirmed: 'Is already registered. Please login.'
      confirmation_period_expired: "Has expired.%{period}You need to confirm by. Please make a new request."
      expired: 'Has expired. Please make a new request.'
      not_found: 'Was not found.'
      not_locked: 'Is not frozen.'
      not_saved:
        one: "Because an error occurred%{resource}Was not saved:"
        other: "%{count}Because an error occurred%{resource}Was not saved:"
      taken: "Is already in use."
      blank: "Is not entered."
      too_short: "Is%{count}Please set more than characters."
      too_long: "Is%{count}Please set below the character."
      invalid: "Is not valid."
      confirmation: "Does not match the content."

Add the User model.

config/locales/models/ja.yml


ja:
  activerecord:
    models:
      recipe:recipe
      user:user
    attributes:
      recipe:
        title:Cooking name
        description:comment
      ingredients:
        name:material
        amount:amount
      user:
        name:username
        email:mail address
        password:password
        password_confirmation:Confirmation password
        remember_me:login automatically from now on

Note that the user name may not be the column name depending on the person. This is completed.

Recommended Posts

Convert error messages to Japanese Supports multiple tables
How to display error messages in Japanese
Japanese localization of error messages
Japanese localization of error messages
Japanese localization of error messages (rails)
I want to eliminate duplicate error messages
The road to Japaneseizing Rails devise error messages
Rails error messages cannot be translated into Japanese
Introduction of Rspec and Japanese localization of error messages
[Rails] How to get success and error messages
[Rails] How to convert UC time display to Japanese time display
[Rails] Save information from one form to multiple tables
[RSpec] How to test error messages set by Shoulda-Matchers