[RUBY] The road to Japaneseizing Rails devise error messages

I'm a Rails beginner. This time, I wanted to translate the error message in Rails' devise login function into Japanese, so I stumbled a little, so I will make a memorandum.

Premise

--The login function of devise has been implemented.

gem installation

devise Added gem for Japanese

Gemfile


 gem 'devise-i18n'
 gem 'devise-i18n-views'
$ bundle install

Generate devise Japanese file

$ rails g devise:views:locale ja
    create  config/locales/devise.views.ja.yml

Japanese error message file is generated

Get Japanese files from devise

Edit config / application.rb

Added config.i18n.default_locale =: ja By default, the English : en is set, so change it to the Japanese: ja.

config/application.rb


module repository name
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 5.2
    #####

    config.i18n.default_locale = :ja

    #####
  end
end

Start with Rails s and try to display the error statement

Screenshot 2020-05-26 17.37.50.png

Although it was translated into Japanese, some English sentences were ... I didn't seem to be able to get a Japanese sentence that matches the error in devise

Add error statement

Editing devise.views.ja.yml

The message is saved in the devise.views.ja.yml file added by $ rails g devise: views: locale ja, so edit it. ** By default, it is written as follows **

ja:
  activerecord:
    attributes:
      user:
 current_password: "current password"
 email: "email address"
 password: "password"
 password_confirmation: "Confirmation password"
 remember_me: "remember login"
    models:
 user: "user"

   .
   .
   .

Looking at the error statement in the browser earlier,

Email address translation missing: ja.activerecord.errors.models.user.attributes.email.blank

It is output as, and this is edited by creating a hierarchy with a yml file.

ja:
  activerecord:
    attributes:
      user:
 current_password: "current password"
 email: "email address"
 password: "password"
 password_confirmation: "Confirmation password"
 remember_me: "remember login"
    models:
 user: "user"

### from here
    errors:
      models:
        user:
          attributes:
            email:
 blank: "Please enter"
            password:
 blank: "Please enter"
            name:
 blank: "Please enter"
### So far

And edit it to display the error statement

Screenshot 2020-05-26 17.59.46.png

I did it well

By the way, I set ja.errors.messages.not_saved.one etc. to blank ʻone:" "` and tried to delete the error count statement and customized it.

Screenshot 2020-05-26 18.09.53.png

Roughly Japanese localization of devise error sentence is like this

Click here for references [Rails5] Japaneseize with Devise-i18n Correcting "translation missing" after Devise Japanese localization github devise-i18n

Recommended Posts

The road to Japaneseizing Rails devise error messages
[Rails] How to display error messages individually
[Ruby on Rails] How to display error messages
[Rails] How to get success and error messages
Japaneseization of Rails error messages [devise / Form objects, etc.]
[Rails] How to install devise
[Rails] Add column to devise
[rails] error during devise installation
[Rails] Processing after adding a column to the devise table
[Rails] Workaround for classes automatically generated by devise error messages
[Rails] How to display error messages for comment function (for beginners)
[Rails] What was the error message?
[Rails] How to use gem "devise"
[Rails] Japanese localization of error messages
[Rails] How to use flash messages
[Rails] Unexpected validation error in devise
[Rails] Display form error messages asynchronously
Japanese localization of error messages (rails)
[Rails] Add strong parameters to devise
The road from JavaScript to Java
[Rails 5] How to display the password change screen when using devise
I want to eliminate duplicate error messages
[Rails] About the error when displaying the screen due to the autofocus of the form
How to put out the error bundling
The road to Web service creation (Part 2)
The road to creating a music game 2
Java SE8 Silver ~ The Road to Pass ~
[Rails] How to use the map method
[Rails error] Your user account isn't allowed to install to the system RubyGems.
Rails tutorial Resolved an error deploying to Heroku, so note the solution
Testing for Error Messages: Rails Tutorial Notes-Chapter 7
[Rails] How to get the user information currently logged in with devise
[Rails] Use devise to get information about the currently logged in user
[Rails] devise
[Note] How to use Rails 6 Devise + cancancan
The process of introducing Vuetify to Rails
The road to creating a music game 3
[Rails] How to translate devise into Japanese
The road to creating a music game 1
How to display error messages in Japanese
[Rails6] How to connect the posting function generated by Scaffold with the user function generated by devise
[Ruby on Rails] How to Japaneseize the error message of Form object (ActiveModel)
[Rails] How to decide the destination by "rails routes"
How to find the cause of the Ruby error
[Rails] Button to return to the top of the page
[Rails] I tried to raise the Rails version from 5.0 to 5.2
[Rails] Let's translate the error message into Japanese
Rails: Japanese localization of validation messages including devise
I tried to organize the session in Rails
The devise error message is not displayed properly.
The code I used to connect Rails 3 to PostgreSQL 10
Rails error messages cannot be translated into Japanese
[Rails] How to solve "Uglifier :: Error: Unexpected character'`'"
Convert error messages to Japanese Supports multiple tables
Error deploying rails5 + Mysql to heroku with Docker-compose
[Rails] Added in devise: username not added to database
Unify the Rails app time zone to Japan time
Try to summarize the common layout with rails
How to check Rails commands in the terminal
The road to creating a Web service (Part 1)
[Ruby on Rails] Individual display of error messages