Module: Tounge::LocaleControl

Defined in:
lib/tounge/locale_control.rb

Class Method Summary collapse

Class Method Details

.included(controller) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tounge/locale_control.rb', line 3

def self.included(controller)
  controller.class_eval do
    before_filter :set_locale

    def set_locale
      LocaleSetter.set_by(default_locale_inputs)
    end

    def default_url_options(options = {})
      if params[:locale]
        { locale: I18n.locale }.merge(options)
      else
        options
      end
    end

    def default_locale_inputs
      { params: params,
        session: session,
        user: current_user,
        http: request.env['HTTP_ACCEPT_LANGUAGE'],
        default: I18n.default_locale }
    end
  end
end