Главная » Статьи » Ruby on Rails

Rails 5. How to set english locale for errors

Rails 5. How to set english locale for errors.

Solution

Create a new file i18n_missing_translations.rb and place there the following code:

i18n_simple_backend = I18n::Backend::Simple.new
old_handler = I18n.exception_handler
I18n.exception_handler = lambda do |exception, locale, key, options|
 case exception
 when I18n::MissingTranslation
 i18n_simple_backend.translate(:en, key, options || {})
 else
 old_handler.call(exception, locale, key, options)
 end
end


Источник: https://coderwall.com/p/ukwpkg/i18n-how-to-load-default-en-locales-instead-of-translation-missing-errors
Категория: Ruby on Rails | Добавил: iamsimakov (2017-04-21)
Просмотров: 531 | Теги: rails, english errors, set en locale for errors | Рейтинг: 0.0/0
Всего комментариев: 0
avatar