--Since the error content played in the validation of the input form when using the Rails Form object pattern is displayed in Japanese, I will summarize it as a memorandum.
--The Rails application uses the Form object pattern.
--One of the implementation patterns in development using Rails. --Mainly used when you want to operate multiple models when submitting one form, or when you want to validate information that does not store information in the table.
--First, when saving data from one form to multiple tables, if you do not use a Form object, in the model related to multiple tables when processing (create or update) the value sent from the form If the input value is flipped by the validation of the description, the process cannot be continued. --The Form object pattern is used to make up for that point. --By describing the validation in the instance of Form object, if the input value from the form is caught in the validation, an error message can be returned to the form together with the input information.
config.i18n.default_locale = :ja ← Add this sentence.
cnofig>application.rb
module (Created application name)
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.0
#Japanese language setting
config.i18n.default_locale = :ja #← Apply this sentence in config.Added to rb.
# 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
end
Gemfil
~Omission~
gem 'rails-i18n'
Terminal
bundle install
Create a locale file for Japanese translation for words that cannot be supported by the rails-i18n Gem. -Locale file: A language file that can handle various languages. -First, create the locales folder in the config folder. -And create a file called "ja.yml" in the config/locales directory.
After creating the ja.yml file, write the English / English words and Japanese translation you want to translate into Japanese in the file. -For the description in the ja.yml file, please refer to the code below.
ja.yml
ja:
activerecord: #← Translation part for the model that inherits ActiveRecord
attributes:
user: #← Model file name
nickname:nickname#←rails-Word names not translated by i18n
gender:sex#←rails-Word names not translated by i18n
age:age#←rails-Word names not translated by i18n
activemodel: #← Translation of Form object pattern created by inheriting ActiveModel to model
attributes:
book_data: #← Model file name using Form object pattern
title:title#←rails-Word names not translated by i18n
publisher:the publisher#←rails-Word names not translated by i18n
author:Author#←rails-Word names not translated by i18n
isbn: ISBN #←rails-Word names not translated by i18n
Recommended Posts