Sha256: 032d68c2407815a63c5b8b79929eb09602b42e45da13de4e15663bc90f55333d
Contents?: true
Size: 1.22 KB
Versions: 3
Compression:
Stored size: 1.22 KB
Contents
module Amalgam module Globalize module Helpers extend ActiveSupport::Concern included do before_filter :set_locale end def set_locale extracted_locale = '' if can_edit? extracted_locale = params[:locale] || extract_locale_from_subdomain || session[:locale] else extracted_locale = params[:locale] || extract_locale_from_subdomain end available_locales = ::I18n::available_locales.collect{|m| m.to_s} ::I18n.locale = (available_locales.include? extracted_locale.to_s) ? extracted_locale : ::I18n.default_locale session[:locale] = extracted_locale if params[:locale] && can_edit? end def default_url_options(options={}) return {} if Amalgam.i18n == 'subdomain' if Amalgam.i18n == 'param' return !options[:locale] ? { :locale => ::I18n.locale.to_s } : {} end {} end protected def extract_locale_from_subdomain res = request.subdomains.first res if !request.subdomains.empty? and res != request.host and ::I18n::available_locales.collect{|m| m.to_s}.include? res end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
amalgam-2.1.4.1 | lib/amalgam/globalize/helpers.rb |
amalgam-2.1.4 | lib/amalgam/globalize/helpers.rb |
amalgam-2.1.3.1 | lib/amalgam/globalize/helpers.rb |