Sha256: 574e6b307ec61946f8c2cf62eb1ec7ebf5e3c45babb1f9e26adf906543811382

Contents?: true

Size: 813 Bytes

Versions: 13

Compression:

Stored size: 813 Bytes

Contents

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  before_action :set_locale

  def set_locale
    I18n.locale = params[:locale] || session[:locale] || locale_from_browser || default_language
    if I18n.locale.to_s != session[:locale].to_s
      logger.debug "Locale changed from -#{session[:locale].to_s}- to -#{I18n.locale.to_s}-."
    end
    session[:locale] = I18n.locale.to_s
  end

  require 'ostruct'
  def current_user
    @current_user ||= OpenStruct.new(name: "John Smith", can_translate?: true)
  end
  helper_method :current_user

  private
    def locale_from_browser
      request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
    end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
i18nline-0.0.15.alpha test/dummy/app/controllers/application_controller.rb
i18nline-0.0.14.alpha test/dummy/app/controllers/application_controller.rb
i18nline-0.0.12.alpha test/dummy/app/controllers/application_controller.rb
i18nline-0.0.11.alpha test/dummy/app/controllers/application_controller.rb
i18nline-0.0.10.alpha test/dummy/app/controllers/application_controller.rb
i18nline-0.0.8.alpha test/dummy/app/controllers/application_controller.rb
i18nline-0.0.7.alpha test/dummy/app/controllers/application_controller.rb
i18nline-0.0.6.alpha test/dummy/app/controllers/application_controller.rb
i18nline-rails-0.0.5.alpha test/dummy/app/controllers/application_controller.rb
i18nline-0.0.5.alpha test/dummy/app/controllers/application_controller.rb
i18nline-0.0.4.alpha test/dummy/app/controllers/application_controller.rb
i18nline-0.0.3.alpha test/dummy/app/controllers/application_controller.rb
i18nline-0.0.2.alpha test/dummy/app/controllers/application_controller.rb