Module: Locomotive::Concerns::LocaleHelpersController

Extended by:
ActiveSupport::Concern
Defined in:
app/controllers/locomotive/concerns/locale_helpers_controller.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#back_to_default_site_localeObject



35
36
37
38
39
40
# File 'app/controllers/locomotive/concerns/locale_helpers_controller.rb', line 35

def back_to_default_site_locale
  # we do force the content locale to the site default locale
  params.delete(:content_locale)

  session[:content_locale] = ::Mongoid::Fields::I18n.locale = current_site.default_locale
end

#current_content_localeObject



11
12
13
# File 'app/controllers/locomotive/concerns/locale_helpers_controller.rb', line 11

def current_content_locale
  ::Mongoid::Fields::I18n.locale
end

#localized?Boolean

Returns:



49
50
51
# File 'app/controllers/locomotive/concerns/locale_helpers_controller.rb', line 49

def localized?
  !!@locomotive_localized
end

#set_current_content_localeObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/locomotive/concerns/locale_helpers_controller.rb', line 15

def set_current_content_locale
  if params[:content_locale].present?
    session[:content_locale] = params[:content_locale]
  end

  unless current_site.locales.include?(session[:content_locale])
    session[:content_locale] = current_site.default_locale
  end

  ::Mongoid::Fields::I18n.locale = session[:content_locale]

  # set also the locale in the session steam uses for the preview
  # This is important because all the sites in preview mode belong to the same domain
  session["steam-locale-#{current_site.handle}"] = session[:content_locale]

  self.setup_i18n_fallbacks

  # logger.debug "*** content locale = #{session[:content_locale]} / #{::Mongoid::Fields::I18n.locale}"
end

#setup_i18n_fallbacksObject



42
43
44
45
46
47
# File 'app/controllers/locomotive/concerns/locale_helpers_controller.rb', line 42

def setup_i18n_fallbacks
  ::Mongoid::Fields::I18n.clear_fallbacks
  (current_site.try(:locales) || []).each do |locale|
    ::Mongoid::Fields::I18n.fallbacks_for(locale, current_site.locale_fallbacks(locale))
  end
end