The topic is simple, but I had to spend some time before I understood from disparate sources how to get validation error messages in Russian most quickly and simply. This post will help save some time for beginners.
Localization files are in config / locales. How it may look for the Russian language can be found here
github.com/svenfuchs/rails-i18n/blob/master/rails/locale/ru.ymlIf we copy this file to our project and write the default Russian language in config / application.rb:
config.i18n.default_locale = :ru
Then we will receive messages of the form:
')
Name
Phone
But I would also like to see Name and Phone in Russian. To do this, create in the config / locale the models folder with the file ru.yml:
ru: activerecord: models: user: attributes: profile: name: " " phone:
Thus we set Russian names for the model and its properties. In order for Rails to pick up the file in application.rb, add the line:
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
And now our error message will be like this:
Own error messages
If for some reason you are not satisfied with the built-in error messages, you can add your own:
Types of validation messages can be found here:
guides.rubyonrails.org/i18n.html#error-message-interpolationThat's all the basics of localization of validation messages in RoR.