[RUBY] [Japanese localization] i18n rails Easy Japanese localization view display only

【goal】

Switch only view to Japanese display

【merit】

■ Improvement of UI ■ Because it is in Japanese, readability is improved and development efficiency is improved.

【Development environment】

■ Mac OS catalina ■ Ruby on Rails (5.2.4.2) ■ Virtual Box:6.1 ■ Vagrant: 2.2.7

【Implementation】

Application creation

mac.terminal


$ rails new japoanese
$ rails g controller homes index
$ cd config/locale
$ touch ja.yml

gemfile.add to


gem 'rails-i18n', '~> 5.1' 

routes.rb


root 'homes#index'

locale/ja.yml


ja:
 homes:
    index:
      title: 'Title'
      name:'name'
      text:‘Sentence’

##The writing style changes a little when the model is related. It looks like the following. .. ..

  activerecord:
    models:
      user: "user"
      attributes:
        user:
        name: "name"
        age: "age"
  

*** The following important **

config/application.rb


config.i18n.default_locale = :ja #add to

homes/index.htmnl.erb



<h2><%= t '.title'%></h2>
<h2><%= t '.name'%></h2>
<h2><%= t '.text'%></h2>

that's all! !!

[I want to read it together]

■ More detailed articles https://qiita.com/shimadama/items/7e5c3d75c9a9f51abdd5

■ Error message https://qiita.com/tanaka-yu3/items/63b189d3f15653cae263

■ rails method for beginners https://qiita.com/tanaka-yu3/items/89abad875187494bec53

Recommended Posts

[Japanese localization] i18n rails Easy Japanese localization view display only
[Rails] Display popular posts in ranking format [Easy]
[Rails] How to display an image in the view
[Rails] Japanese localization using rails-i18n
Display Flash messages in Rails
View monthly calendar in Rails
From Ruby on Rails error message display to Japanese localization
[Rails] How to display information stored in the database in view
[Rails] How to write in Japanese
[Rails] Validation settings and Japanese localization
Japanese localization of error messages (rails)
[rails] How to display parent information in child view in nested relationships
Specify home view in rails app [root]
[Rails] Store only checked items in DB
How to display error messages in Japanese
Rails: Japanese localization of validation messages including devise
Display around fonts in Japanese with Swift: macOS
How to translate Rails into Japanese in general
[Rails] Japanese localization of validation error message ~ ja.yml ~
Implement iteration in View by rendering collection [Rails]
Display text character by character in Android Surface View
Simple notification function in Rails (only when followed)
Easy to display hello world with Rails + Docker
[Rails] How to convert UC time display to Japanese time display
Group_by in Rails
[Rails] View sharing
[Rails] How to display the weather forecast of the registered address in Japanese using OpenWeatherMap
How to set the display time to Japan time in Rails
[Ruby on Rails] How to write enum in Japanese
Some subtly different repetitive writing styles in Rails View
Change date and time to Japanese notation in Rails
[Rails] How to load JavaScript in a specific view
[Rails] Create initial data with seed.rb [Faker] [Japanese localization]
Do not write 〇〇 logic in Rails View (* added later)