Change the notation in enum to Japanese
ruby 2.5.7 Rails 5.2.4.3 OS: macOS Catalina
Introduced 1 gem 2 Edit config / application.rb 3 Create and edit config / locales / ja.yml 4 Change view
This time we will introduce gem'rails-i18n' and gem'enum_help'.
Gemfile
gem 'rails-i18n'
gem 'enum_help'
Terminal
$ bundle install
Add the following 4 lines to config.load_defaults.
config/application.rb
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.
end
Create ja.yml under config / locales.
config/locales/ja.yml
ja:
enums:
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
Add _i18n after the column you want to write in Japanese.
erb:app/views/homes/about.html.erb
<%= @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