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.
--The login function of devise has been implemented.
gem 'devise-i18n' gem 'devise-i18n-views'
＄ bundle install
$ rails g devise:views:locale ja create config/locales/devise.views.ja.yml
Japanese error message file is generated
config.i18n.default_locale =: ja
By default, the English
: en is set, so change it to the Japanese
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
Rails s and try to display the error statement
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
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
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.
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