Module: Amalgam::Globalize::Helpers

Extended by:
ActiveSupport::Concern
Included in:
ApplicationController
Defined in:
lib/amalgam/globalize/helpers.rb

Instance Method Summary collapse

Instance Method Details

#default_url_options(options = {}) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/amalgam/globalize/helpers.rb', line 28

def default_url_options(options={})
  return {} if Amalgam.i18n == 'subdomain'
  if Amalgam.i18n == 'param'
    return !options[:locale] ? { :locale => ::I18n.locale.to_s } : {}
  end
  {}
end

#set_localeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/amalgam/globalize/helpers.rb', line 9

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