Introduction of Rspec and Japanese localization of error messages

Introduction

A memorandum for myself. It's a hassle to check the procedure every time, so try to put together your own package.

procedure

Rspec

Install Gem

Gemfile


#Omission

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  #Postscript
  gem 'rspec-rails'
  gem 'factory_bot_rails'
  gem 'faker'
end

#Omission

Install Rspec in your application

Terminal


% rails g rspec:install

rspec file configuration

.rspec


--require spec_helper
#Postscript
--format documentation

Japanese localization of error messages

Install Gem

Gemfile


#Bottom
gem 'rails-i18n'

Edit application.rb

config/application.rb


#Omission

module App
 class Application < Rails::Application
   # Initialize configuration defaults for originally generated Rails version.
   config.load_defaults 6.0

   #Postscript
   config.i18n.default_locale = :ja
  #abridgement
 end
end

yml file creation (devise)

config/locales/devise.ja.yml =>Create

yml file edit (devise)

Below, copy and paste

ruby:config/locales/devise.ja.yml


ja:
  activerecord:
    attributes:
      user:
        confirmation_sent_at:Password confirmation transmission time
        confirmation_token:Password confirmation token
        confirmed_at:Password confirmation time
        created_at:Created date
        current_password:Current password
        current_sign_in_at:Current login time
        current_sign_in_ip:Current login IP address
        email:mail address
        encrypted_password:Encrypted password
        failed_attempts:Number of failed login attempts
        last_sign_in_at:Last login time
        last_sign_in_ip:Last login IP address
        locked_at:Lock time
        password:password
        password_confirmation:For password confirmation)
        remember_created_at:Login memory time
        remember_me:Remember login
        reset_password_sent_at:Password reset transmission time
        reset_password_token:Password reset token
        sign_in_count:Login count
        unconfirmed_email:Unconfirmed email
        unlock_token:Unlock token
        updated_at:Update date
    models:
      user:User
  devise:
    confirmations:
      confirmed:I was able to confirm my email address.
      new:
        resend_confirmation_instructions:Resend account confirmation email
      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 an email to verify your identity 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 password is incorrect."
      last_attempt:If you make another mistake, your account will be locked.
      locked:Your account is frozen.
      not_found_in_database: "%{authentication_keys}Or password is incorrect."
      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:
        action:Confirm your email address
        greeting: "%{recipient}Mr"
        instruction:Click the link below to complete the email address verification process.
        subject:Email address confirmation email
      email_changed:
        greeting:Hello,%{recipient}Mr.
        message:Change your email (%{email}) Will be announced.
        subject:Email change completed.
      password_change:
        greeting: "%{recipient}Mr"
        message:Notifies you that your password has been reset.
        subject:About changing password
      reset_password_instructions:
        action:Change Password
        greeting: "%{recipient}Mr"
        instruction:I am sending an email because I received a request to reset my password. You can reset your password from the link below.
        instruction_2:If you have not requested to reset your password, please ignore this email.
        instruction_3:Password reset will not be completed until you register a new password from the link above.
        subject:About resetting password
      unlock_instructions:
        action:Account unlock
        greeting: "%{recipient}Mr"
        instruction:Click the link below to unlock your account.
        message:Your account is locked due to repeated login failures.
        subject:About unfreezing your account
    omniauth_callbacks:
      failure: "%{kind}Failed to authenticate with your account. Reason:(%{reason})"
      success: "%{kind}You have successfully authenticated with your account."
    passwords:
      edit:
        change_my_password:change the password
        change_your_password:Change password
        confirm_new_password:New password for confirmation
        new_password:new password
      new:
        forgot_your_password:Did you forget your password??
        send_me_reset_password_instructions:Send how to reset your password
      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.
      edit:
        are_you_sure:Are you really sure?
        cancel_my_account:Account deletion
        currently_waiting_confirmation_for_email: "%{email}Waiting for confirmation"
        leave_blank_if_you_don_t_want_to_change_it:If left blank, do not change
        title: "%{resource}Edit"
        unhappy:I don't like it
        update:update
        we_need_your_current_password_to_confirm_your_changes:Please enter your current password for the changes to take effect
      new:
        sign_up:account registration
      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.
      updated_but_not_signed_in:Your account has been successfully updated, but your password has changed, so please log in again.
    sessions:
      already_signed_out:You have already logged out.
      new:
        sign_in:Login
      signed_in:You are now logged.
      signed_out:logged out.
    shared:
      links:
        back:Return
        didn_t_receive_confirmation_instructions:Did you receive an account confirmation email??
        didn_t_receive_unlock_instructions:Have you received an email on how to unfreeze your account??
        forgot_your_password:Did you forget your password??
        sign_in:Login
        sign_in_with_provider: "%{provider}Login with"
        sign_up:account registration
      minimum_password_length: "(%{count}More than letters)"
    unlocks:
      new:
        resend_unlock_instructions:Resend account unfreeze method
      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."

yml file creation (general)

config/locales/ja.yml =>Create

yml file editing (general)

config/locales/ja.yml


ja:
  time:
    formats:
      default: "%m/%d %H:%M"
  activerecord:
    attributes:
Model ①:
Column ①:Corresponding Japanese
Column ②:Corresponding Japanese
Model ②:
Column ①:Corresponding Japanese
Column ②:Corresponding Japanese
  #If you are using ActiveModel, continue adding
 activemodel:
    attributes:
Model name:
Column name:Corresponding Japanese

in conclusion

I remembered it because I missed something every time.

I would like to be able to write a program that automates this series of settings.

✔︎

Recommended Posts

Introduction of Rspec and Japanese localization of error messages
Japanese localization of error messages
[Rails] Japanese localization of error messages
Japanese localization of error messages (rails)
Japanese localization of CentOS 8 and Japanese keyboard layout
Japanese localization of Ubuntu20.04
Rails: Japanese localization of validation messages including devise
[Rails] Japanese localization of validation error message ~ ja.yml ~
Japanese localization of Eclipse
[Japanese localization of gem: devise]
Japanese localization of Docker container of CentOS7 / CentOS8 and Japan time setting
[Rails] Japanese localization of error message when using Form object
[Rails] Validation settings and Japanese localization
Animated display of Swift error messages
STS installation and Japanese localization on Windows 10
Introduction of Docker Hub and commands Self-learning ①
Introduction and precautions of gem Friendly Id
Introduction and usage explanation of Font Awesome
How to display error messages in Japanese
[Ruby on Rails] Until the introduction of RSpec
Introduction and basic usage of Simple Calendar gem
Rails error messages cannot be translated into Japanese
How to use enum (introduction of Japanese notation)
[Java] Classification memo of compilation error and run-time error
Convert error messages to Japanese Supports multiple tables
[Rails] How to get success and error messages
Introduction and introduction of management screen generation gem Administrate
[Ruby on Rails] Individual display of error messages
Rspec introduction memo_Rails
Introduction of pay.jp
Use of Japanese fonts and external characters in JasperReport
Japaneseization of Rails error messages [devise / Form objects, etc.]
[RSpec] How to test error messages set by Shoulda-Matchers
Spring Tool Suite installation and Japanese localization for Windows