Allow locale to be set through the front-end
* Store the last used locale in the session * Allow home page to be identified in helpers even when containing parameters * Create initializer to explicitly set the available locales, the default and the load_path
This commit is contained in:
@@ -4,7 +4,21 @@ class ApplicationController < ActionController::Base
|
||||
self.responder = ApplicationResponder
|
||||
respond_to :html
|
||||
|
||||
before_action :set_locale
|
||||
|
||||
# Prevent CSRF attacks by raising an exception.
|
||||
# For APIs, you may want to use :null_session instead.
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
private
|
||||
|
||||
def set_locale
|
||||
if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym)
|
||||
session[:locale] = params[:locale]
|
||||
end
|
||||
|
||||
session[:locale] ||= I18n.default_locale
|
||||
|
||||
I18n.locale = session[:locale]
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user