parent
bd87e66679
commit
bd1545de5e
4 changed files with 17 additions and 21 deletions
|
@ -138,11 +138,7 @@ class ApplicationController < ActionController::Base
|
|||
def respond_with_error(code)
|
||||
respond_to do |format|
|
||||
format.any { head code }
|
||||
|
||||
format.html do
|
||||
set_locale
|
||||
render "errors/#{code}", layout: 'error', status: code
|
||||
end
|
||||
format.html { render "errors/#{code}", layout: 'error', status: code }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,16 +4,19 @@ module Localized
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
before_action :set_locale
|
||||
around_action :set_locale
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_locale
|
||||
I18n.locale = default_locale
|
||||
I18n.locale = current_user.locale if user_signed_in?
|
||||
rescue I18n::InvalidLocale
|
||||
I18n.locale = default_locale
|
||||
locale = current_user.locale if respond_to?(:user_signed_in?) && user_signed_in?
|
||||
locale ||= session[:locale] ||= default_locale
|
||||
locale = default_locale unless I18n.available_locales.include?(locale.to_sym)
|
||||
|
||||
I18n.with_locale(locale) do
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
def default_locale
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue