lib/locale_setter/generic.rb in locale_setter-0.3.0 vs lib/locale_setter/generic.rb in locale_setter-0.4.0
- old
+ new
@@ -1,15 +1,17 @@
module LocaleSetter
module Generic
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_http(options[:env], available(i18n)) ||
+ 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
def self.available(i18n)
i18n.available_locales.map(&:to_s)
@@ -23,12 +25,16 @@
if env && env[HTTP_HEADER]
LocaleSetter::HTTP.for(env[HTTP_HEADER], available)
end
end
+ def self.from_domain(domain, available)
+ LocaleSetter::Domain.for(domain, available)
+ end
+
def self.from_params(params, available)
- if params && params[URL_PARAM]
- LocaleSetter::Param.for(params[URL_PARAM], available)
+ if params && params[LocaleSetter.config.url_param]
+ LocaleSetter::Param.for(params[LocaleSetter.config.url_param], available)
end
end
end
end
\ No newline at end of file