Rails: Japanese localization of validation messages including devise

At first

** 22nd day of calendar planning 2020 ** It's been about 3 months since I started studying programming, so I will leave a note of what I learned in the article as an output. I would be happy if I could help anyone entering the world of programming. Please let me know if there are any words that are wrong, wrong, or misunderstood ^^ I'm sorry if it's hard to read the words for a long time. I will do my best to get used to it little by little.

Japaneseize validation messages including devise

If it is supposed to be used by Japanese people, it is better to use Japanese in the application! That's why I make a note of what I worked on in Japanese.

things to do

  1. Describe in config/application.rb.
  2. Create new "ja.yml" and "devise.ja.yml" under config/locales
  3. Copy and paste the contents of the newly created file with the help of our predecessors.
  4. The column name is probably still in English, so write it in ja.yml by yourself.

that's all

1. Describe in config/application.rb

config/application.rb



config.i18n.default_locale = ja

Please describe in the file.

2. Create new "ja.yml" and "devise.ja.yml" under config/locales

Like this

スクリーンショット 2020-12-22 10.56.07.png

(I don't think you need en.yml, but I'm scared and haven't erased it ^^; It seems that you can create devise.ja.yml in one shot, so please check it if you are interested.)

3. Copy and paste the contents of the newly created file with the help of our predecessors

Borrow while thanking the ancestors ^^

ja.yml devise.ja.yml

4. The column name is probably still in English, so write it in ja.yml by yourself.

config/locales/ja.yml



ja:
  activerecord:
    models:
      member: "member"
      post: "Post"
    attributes:
      member:
        first_name: "Surname"
        last_name: "Name"
        email: "mail address"
        encrypted_password: "password"
      post:
        title: "title"
        body: "Contents"

I added something like this.

Finally

I think it's okay to do all the columns, but I've only done what is displayed, such as where it's used in the error statement.

Also, some people have separated ja.yml for model. I thought it was easier to manage after I finished making it.

Reference site It may be easier to manage if you do it like this. I haven't done it yet, so I'll try it next time.

Recommended Posts

Rails: Japanese localization of validation messages including devise
[Rails] Japanese localization of error messages
Japanese localization of error messages (rails)
[Rails] Japanese localization of validation error message ~ ja.yml ~
Japanese localization of error messages
Japanese localization of error messages
[Japanese localization of gem: devise]
[Rails] Validation settings and Japanese localization
Japanese localization of Ubuntu20.04
[Rails] Customize devise validation
Introduction of Rspec and Japanese localization of error messages
Japanese localization of Eclipse
Japaneseization of Rails error messages [devise / Form objects, etc.]
[Rails] Cancel / change the default password validation of devise
[Rails] Introduction of devise Basics
[Rails] Japanese longest surname (validation)
[Rails] Japanese localization using rails-i18n
[Rails] Japanese localization of error message when using Form object
Summary of rails validation (for myself)
[Rails] Unexpected validation error in devise
Validation of log messages using mockito
Japanese localization of CentOS 8 and Japanese keyboard layout
[Ruby on Rails] Japanese notation of errors
[Rails] devise
[Rails] Implementation of validation that maintains uniqueness
[Rails] How to translate devise into Japanese
The road to Japaneseizing Rails devise error messages
Rails error messages cannot be translated into Japanese
[Japanese localization] i18n rails Easy Japanese localization view display only
[Note] Summary of rails login function using devise ①
[Ruby on Rails] Individual display of error messages
Customization of validation
[rails] Set validation
[Rails] Introducing devise
rails + devise + devise_token_auth
[Rails5] Rspec -validation-
Implementation of Ruby on Rails login function (devise edition)
[Rails] Initial setting of user-created login with devise, devise_token_auth
Explanation of Ruby on rails for beginners ⑥ ~ Creation of validation ~
[Rails] Create initial data with seed.rb [Faker] [Japanese localization]