Sha256: 95dd8c9991d6436927158303cf37d44aa92fffc8d884a5c82a7d8774bffb4f5c

Contents?: true

Size: 1.57 KB

Versions: 23

Compression:

Stored size: 1.57 KB

Contents

module Locomotive
  module Concerns
    module LocaleHelpersController

      extend ActiveSupport::Concern

      included do
        helper_method :current_content_locale, :localized?
      end

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

      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]

        self.setup_i18n_fallbacks

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

      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

      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

      def localized?
        !!@locomotive_localized
      end

      module ClassMethods

        def localized(enable_it = true)
          before_filter do |c|
            c.instance_variable_set(:@locomotive_localized, enable_it)
          end
        end

      end

    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
locomotivecms-3.3.0 app/controllers/locomotive/concerns/locale_helpers_controller.rb
locomotivecms-3.3.0.rc3 app/controllers/locomotive/concerns/locale_helpers_controller.rb
locomotivecms-3.3.0.rc2 app/controllers/locomotive/concerns/locale_helpers_controller.rb
locomotivecms-3.1.2 app/controllers/locomotive/concerns/locale_helpers_controller.rb
locomotivecms-3.2.1 app/controllers/locomotive/concerns/locale_helpers_controller.rb
locomotivecms-3.3.0.rc1 app/controllers/locomotive/concerns/locale_helpers_controller.rb
locomotivecms-3.2.0 app/controllers/locomotive/concerns/locale_helpers_controller.rb
locomotivecms-3.2.0.rc2 app/controllers/locomotive/concerns/locale_helpers_controller.rb
locomotivecms-3.2.0.rc1 app/controllers/locomotive/concerns/locale_helpers_controller.rb
locomotivecms-3.1.1 app/controllers/locomotive/concerns/locale_helpers_controller.rb
locomotivecms-3.1.0 app/controllers/locomotive/concerns/locale_helpers_controller.rb
locomotivecms-3.1.0.rc3 app/controllers/locomotive/concerns/locale_helpers_controller.rb
locomotivecms-3.1.0.rc2 app/controllers/locomotive/concerns/locale_helpers_controller.rb
locomotivecms-3.1.0.rc1 app/controllers/locomotive/concerns/locale_helpers_controller.rb
locomotivecms-3.0.1 app/controllers/locomotive/concerns/locale_helpers_controller.rb
locomotivecms-3.0.0 app/controllers/locomotive/concerns/locale_helpers_controller.rb
locomotivecms-3.0.0.rc7 app/controllers/locomotive/concerns/locale_helpers_controller.rb
locomotivecms-3.0.0.rc6 app/controllers/locomotive/concerns/locale_helpers_controller.rb
locomotivecms-3.0.0.rc5 app/controllers/locomotive/concerns/locale_helpers_controller.rb
locomotivecms-3.0.0.rc4 app/controllers/locomotive/concerns/locale_helpers_controller.rb