Module: LocaleSetter::Generic

Defined in:
lib/locale_setter/generic.rb

Class Method Summary collapse

Class Method Details

.available(i18n) ⇒ Object



16
17
18
# File 'lib/locale_setter/generic.rb', line 16

def self.available(i18n)
  i18n.available_locales.map(&:to_s)
end

.from_domain(domain, available) ⇒ Object



30
31
32
# File 'lib/locale_setter/generic.rb', line 30

def self.from_domain(domain, available)
  LocaleSetter::Domain.for(domain, available)
end

.from_http(env, available) ⇒ Object



24
25
26
27
28
# File 'lib/locale_setter/generic.rb', line 24

def self.from_http(env, available)
  if env && env[HTTP_HEADER]
    LocaleSetter::HTTP.for(env[HTTP_HEADER], available)
  end
end

.from_params(params, available) ⇒ Object



34
35
36
37
38
# File 'lib/locale_setter/generic.rb', line 34

def self.from_params(params, available)
  if params && params[LocaleSetter.config.url_param]
    LocaleSetter::Param.for(params[LocaleSetter.config.url_param], available)
  end
end

.from_user(user, available) ⇒ Object



20
21
22
# File 'lib/locale_setter/generic.rb', line 20

def self.from_user(user, available)
  LocaleSetter::User.for(user, available)
end

.set_locale(i18n, options = {:params => nil, :user => nil, :domain => nil, :env => nil}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/locale_setter/generic.rb', line 4

def self.set_locale(i18n, options = {:params => nil,
                                     :user   => nil,
                                     :domain => nil,
                                     :env    => nil})

  i18n.locale = from_params(options[:params], available(i18n)) ||
                from_user(options[:user], available(i18n))     ||
                from_domain(options[:domain], available(i18n)) ||
                from_http(options[:env], available(i18n))      ||
                i18n.default_locale
end