Japaneseize using i18n with Rails

Thing you want to do

--I want to replace the parts written in English such as error messages with Japanese. --When displaying DB column names and class attributes, I want to display the ones that have been replaced with Japanese in advance.

Conclusion

--Introduce gem's rails-i18n --Set the word you want to convert in the ja.yml file

manner

--Introduce gem's rails-i18n

Gemfile


#The place to write is at the bottom of the file or group:development, group :development, :Described in a place other than test
gem 'rails-i18n'

--Install gem --Set the ** default locale in config / application.rb to ja **

application.rb


#↑ Codes above this are omitted
module App
  class Application < Rails::Application
    config.i18n.default_locale = :ja
    config.time_zone = 'Tokyo'
  end
end

--Create a file of config / locales / ja.yml --In ja.yml, describe the settings you want to convert to Japanese in yml format
Example: Characters related to DB columns → ʻactiverecord: attributes: Model name: <br /> Characters related to view → views: resource name:`

ja.yml


ja:
  activerecord:
    attributes:
      user:
        name:username
        email:Email
        password:password
        password_confirmation:Password confirmation)
      tweet:
        name:name
        title:title
        body:Text
      comment:
        name:name
        comment:comment
  views:
    pagination:
      first:the first
      last:last
      previous:Before
      next:Next
      truncate: ...

--When the settings are complete, restart the server (because it will not be reflected unless you do this)

Recommended Posts

Japaneseize using i18n with Rails
Notes on using FCM with Ruby on Rails
Group_by in Rails
Implement button transitions using link_to in Rails
Sign in with Apple using gem's apple_id in Rails and cache Apple's JWK
Create authentication function in Rails application using devise
Implement share button in Rails 6 without using Gem
[Rails] Run LINEBot in local environment using ngrok
Implement star rating function using Raty in Rails6
[Rails] Show avatars in posts using Active Storage
Model association in Rails
Using Pair with OpenJDK
[Rails 6] RuntimeError with $ rails s
Disable turbolinks in Rails
Handle devise with Rails
[Rails] Learning with Rails tutorial
^, $ in Rails regular expression
[Rails] Test with RSpec
Use images in Rails
[Rails] Development with MySQL
Understand migration in rails
Supports multilingualization with Rails!
Split routes.rb in Rails6
Implement markdown in Rails
Write beautiful code with indentation in mind (rails, html)
Multi-tenant with Rails using PostgreSQL's Row Level Security Policy
[How to insert a video in haml with Rails]
Using PAY.JP API with Rails ~ Implementation Preparation ~ (payjp.js v2)
How to query Array in jsonb with Rails + postgres
Using PAY.JP API with Rails ~ Card Registration ~ (payjp.js v2)
Get UserAgent in [Rails] controller
Implement application function in Rails
Log output in Json format using lograge / lograge-sql with RubyOnRails
[Rails] Fade out flash messages with javascript without using jquery
How to set environment variables when using Payjp with Rails
Try using RocksDB in Java
Search function using [rails] ransack
[Rails] Express polymorphic with graphql-ruby
Try using GloVe with Deeplearning4j
[Rails] Upload videos with Rails (ActiveStorage)
SNS authentication using Rails google
[Rails] Save images using carrierwave
[Vue Rails] "Hello Vue!" Displayed with Vue + Rails
Be careful of initialization timing when using MessageEncryptor with Rails 5.2 / 6.0
[Rails] Japanese localization using rails-i18n
Implement LTI authentication in Rails
Preparation for developing with Rails
Run Rails whenever with docker
Gem often used in Rails
How to deploy jQuery in your Rails app using Webpacker
[Rails] Test code using Rspec
[Docker] Rails 5.2 environment construction with docker
Use multiple databases with Rails 6.0
Using Mapper with Java (Spring)
[Rails] Specify format with link_to
I came across a guy with two dots in Rails
Get Youtube channel information with Rails app (using Yt gem)
View monthly calendar in Rails
Display API definition in Swagger UI using Docker + Rails6 + apipie
Using Amateurs UML in Eclipse
Error when using rails capybara