[RUBY] [Rails] Japanese localization using rails-i18n

Introduction

By using the gem called rails-i18n, error messages etc. can be translated into Japanese.

table of contents

  1. Set the language to Japanese
  2. Install rails-i18n
  3. Create a file to set to Japanese

1. Set the language to Japanese

Edit application.rb.
You can set it to Japanese by setting **: ja **.

config/application.rb



module CosmeticReview
  class Application < Rails::Application
    config.load_defaults 6.0
    #Add the following description
    config.i18n.default_locale = :ja
  end
end

2. Install rails-i18n

Add the following to the gemfile. Then run bundle install with the command.

gemfile


gem 'rails-i18n'

3. Create a file to set to Japanese

Create a local file and create a YAML file in it for translation into Japanese. This time, the error message of the model has been translated into Japanese.

locales/ja.yml


ja:
 activerecord:
   attributes:
     user:
       nickname:nickname
       gender:sex
       introduce:Self-introduction
       birthday:Birthday
     post:
       name:Product name
       description:Product description
       image:image
       shop_name:Where to buy
       evaluation:Product evaluation
       price:Purchase price
       category_id:Category
   time:
     formats:
       default: "%Y/%m/%d %H:%M:%S"

Be careful as an error will occur if the hierarchy is off even a little.

Reference link

https://github.com/svenfuchs/rails-i18n

Recommended Posts

[Rails] Japanese localization using rails-i18n
[Rails] Japanese localization of error messages
[Rails] Validation settings and Japanese localization
Japanese localization of error messages (rails)
[Rails] Japanese localization of error message when using Form object
Rails: Japanese localization of validation messages including devise
[Rails] Japanese localization of validation error message ~ ja.yml ~
[Japanese localization] i18n rails Easy Japanese localization view display only
Japanese localization of Ubuntu20.04
Japanese localization of Eclipse
[Rails] Create initial data with seed.rb [Faker] [Japanese localization]
Japanese localization of error messages
Japanese localization of error messages
Search function using [rails] ransack
Try using view_component with rails
[Rails] Japanese longest surname (validation)
SNS authentication using Rails google
[Rails] Save images using carrierwave
Japaneseize using i18n with Rails
[Japanese localization of gem: devise]
From Ruby on Rails error message display to Japanese localization
[Rails] Test code using Rspec
Organize Rails routing using draw
Ajax bookmark function using Rails
Error when using rails capybara
[Rails] Try using Faraday middleware
Detailed tips when using Rails
[Rails 6] Star-shaped review using Raty.js
[Rails] Creation of the second vertical axis and Japanese localization in graph drawing using amCharts4, etc.
[Hidden_field] Let's send information using rails hidden_field !!!!
[Rails] How to write in Japanese
Get PV (views) using Impressionist ~ Rails
[Rails] Tag management function (using acts-as-taggable-on)
[Rails 6] API development using GraphQL (Query)
[Rails 6] destroy using the resources method
[Rails] Status update using Rake task
[Rails] Reflection to db using seeds.rb