Sha256: ad1aae2cd9674e1ae4f001fcc01172c28f1482a1effc9f28ea91eacfb9687e89
Contents?: true
Size: 1.52 KB
Versions: 3
Compression:
Stored size: 1.52 KB
Contents
module RailsLocaleDetection module DetectionMethods # returns the (symbolized) value passed if it's in the available_locales def validate_locale(locale) locale.to_sym if locale && available_locales.include?(locale.to_sym) end def locale_from_param validate_locale(params[locale_key]) end def locale_from_cookie validate_locale(cookies[locale_key]) end def locale_from_request validate_locale(request.preferred_language_from(available_locales)) end def locale_from_user validate_locale(user_locale) end def locale_from(key) send("locale_from_#{key}") end def detect_locale RailsLocaleDetection.detection_order.inject(nil) { |result, source| result || locale_from(source) } || default_locale end # set I18n.locale, default_url_options[:locale] and cookies[:locale] to the value returned by # detect_locale def set_locale self.current_locale = detect_locale default_url_options[locale_key] = current_locale if set_default_url_option_for_request? cookies[locale_key] = { :value => current_locale, :expires => RailsLocaleDetection.locale_expiry.from_now } end # returns true if the default url option should be set for this request def set_default_url_option_for_request? RailsLocaleDetection.set_default_url_option === true || RailsLocaleDetection.set_default_url_option == :always || RailsLocaleDetection.set_default_url_option == :explicitly && params[locale_key].present? end end end
Version data entries
3 entries across 3 versions & 1 rubygems