[RUBY] 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
Japaneseize using i18n with Rails
Succeeded in loading js manually compiled using webpack with rails6
Things to keep in mind when using Sidekiq with Rails
Notes on using FCM with Ruby on Rails
Group_by in Rails
Implement button transitions using link_to in Rails
Using Material Design for Bootstrap with Rails 5.2
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
One way to redirect_to with parameters in rails
[Rails] Show avatars in posts using Active Storage
Implement the Like feature in Ajax with Rails.
Model association in Rails
Adding columns in Rails
Using Pair with OpenJDK
[Rails 6] RuntimeError with $ rails s
Disable turbolinks in Rails
CSRF measures 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
Double polymorphic with Rails
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
Log output in Json format using lograge / lograge-sql with RubyOnRails
[Rails] Fade out flash messages with javascript without using jquery
Try using RocksDB in Java
Introduced graph function with rails
Search function using [rails] ransack
[Rails] Express polymorphic with graphql-ruby
[Rails] Upload videos with Rails (ActiveStorage)
SNS authentication using Rails google
Implement follow function in Rails
[Rails] Save images using carrierwave
exited with code 1 error resolution with docker-compose up in rails environment
[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
API creation with Rails + GraphQL
Preparation for developing with Rails
Error in rails db: migrate
Run Rails whenever with docker
Gem often used in Rails
Display Flash messages in Rails