[Ruby on Rails] How to write enum in Japanese


Change the notation in enum to Japanese

Development environment

ruby 2.5.7 Rails OS: macOS Catalina



Introduced 1 gem 2 Edit config / application.rb 3 Create and edit config / locales / ja.yml 4 Change view

Introduced gem

This time we will introduce gem'rails-i18n' and gem'enum_help'.


gem 'rails-i18n'
gem 'enum_help'


$ bundle install

Edit config / application.rb

Add the following 4 lines to config.load_defaults.


  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 5.2
    config.paths.add 'lib', eager_load: true
    config.time_zone = 'Tokyo'
    config.i18n.default_locale = :ja
    config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]

    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration can go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded after loading
    # the framework and any gems in your application.

Create and edit config / locales / ja.yml

Create ja.yml under config / locales.


    talk: #Model name
      contributor: #Column name
        customer: 'Member' #enum value
        shop: 'Store' #enum value
        admin: 'Administrator' #enum value
    customer: #Model name
      privacy: #Column name
        published:Release#enum value
        closed:private#enum value

Change view

Add _i18n after the column you want to write in Japanese.


<%= @talk.contributor_i18n %>


Click here for the Japanese notation of the error [https://qiita.com/japwork/items/aba5a5883d0588ce926f) Click here for the notation that you like the update date and creation date (https://qiita.com/japwork/items/25adc4c78be4230bb591)

Recommended Posts

[Ruby on Rails] How to write enum in Japanese
[Rails] How to write in Japanese
[Ruby on Rails] How to install Bootstrap in Rails
How to use Ruby on Rails
[Ruby On Rails] How to reset DB in Heroku
Rails on Tiles (how to write)
How to display a graph in Ruby on Rails (LazyHighChart)
[Ruby on Rails] How to use CarrierWave
[Ruby on Rails] How to use redirect_to
[Ruby on Rails] How to use kaminari
How to write Rails
[Ruby on Rails] How to display error messages
How to add / remove Ruby on Rails columns
JUnit 5: How to write test cases in enum
How to translate Rails into Japanese in general
[Ruby on Rails] How to use session method
Notes on how to write comments in English
How to create a query using variables in GraphQL [Using Ruby on Rails]
[Rails] How to use enum
[Rails] How to use enum
How to implement gem "summer note" in wysiwyg editor in Ruby on Rails
How to write Rails validation
How to write Rails seed
[Ruby] How to write blocks
How to debug the processing in the Ruby on Rails model only on the console
How to write Rails routing
[Ruby on Rails] How to change the column name
How to write a date comparison search in Rails
(Ruby on Rails6) How to create models and tables
How to resolve errors that occur in the "Ruby on Rails" integration test
How to implement image posting function using Active Storage in Ruby on Rails
How to deploy jQuery on Rails
How to iterate infinitely in Ruby
How to deploy Bootstrap on Rails
Ruby on Rails Japanese-English support i18n
How to install Bootstrap in Ruby
[Rails] How to write exception handling?
How to introduce jQuery in Rails 6
How to install Swiper in Rails
From Ruby on Rails error message display to Japanese localization
Apply CSS to a specific View in Ruby on Rails
[Rails5] japanMap link How to write parameters in js.erb file
[Rails] How to write user_id (foreign key) in strong parameter
How to implement search functionality in Rails
How to change app name in rails
How to get date data in Ruby
How to use custom helpers in rails
How to insert a video in Rails
[RSpec on Rails] How to write test code for beginners by beginners
Ruby on Rails in Visual Studio Codespaces
How to use MySQL in Rails tutorial
How to write ruby if in one line Summary by beginner
Deploy to Heroku [Ruby on Rails] Beginner
Preparing to introduce jQuery to Ruby on Rails
[rails] How to configure routing in resources
[Ruby on Rails] Japanese notation of errors
[Ruby on Rails] "|| =" ← Summary of how to use this assignment operator
How to implement ranking functionality in Rails
Beginners create portfolio in Ruby on Rails
Things to remember and concepts in the Ruby on Rails tutorial
[Ruby on Rails] Button to return to top