Sha256: 72e872b858024e50692256216f1b16b2b40e133331c3a50bbb1b96601cb9bd84

Contents?: true

Size: 1.66 KB

Versions: 18

Compression:

Stored size: 1.66 KB

Contents

module Locomotive
  module ActionController
    module LocaleHelpers

      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 set_back_office_locale
        ::I18n.locale = current_locomotive_account.locale rescue Locomotive.config.default_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
        (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

18 entries across 18 versions & 1 rubygems

Version Path
locomotive_cms-2.5.7 lib/locomotive/action_controller/locale_helpers.rb
locomotive_cms-2.5.6 lib/locomotive/action_controller/locale_helpers.rb
locomotive_cms-2.5.6.rc2 lib/locomotive/action_controller/locale_helpers.rb
locomotive_cms-2.5.6.rc1 lib/locomotive/action_controller/locale_helpers.rb
locomotive_cms-2.5.5 lib/locomotive/action_controller/locale_helpers.rb
locomotive_cms-2.5.4 lib/locomotive/action_controller/locale_helpers.rb
locomotive_cms-2.5.3 lib/locomotive/action_controller/locale_helpers.rb
locomotive_cms-2.5.2 lib/locomotive/action_controller/locale_helpers.rb
locomotive_cms-2.5.1 lib/locomotive/action_controller/locale_helpers.rb
locomotive_cms-2.5.0 lib/locomotive/action_controller/locale_helpers.rb
locomotive_cms-2.5.0.rc3 lib/locomotive/action_controller/locale_helpers.rb
locomotive_cms-2.5.0.rc2 lib/locomotive/action_controller/locale_helpers.rb
locomotive_cms-2.5.0.rc1 lib/locomotive/action_controller/locale_helpers.rb
locomotive_cms-2.4.1 lib/locomotive/action_controller/locale_helpers.rb
locomotive_cms-2.4.0 lib/locomotive/action_controller/locale_helpers.rb
locomotive_cms-2.3.1 lib/locomotive/action_controller/locale_helpers.rb
locomotive_cms-2.3.0 lib/locomotive/action_controller/locale_helpers.rb
locomotive_cms-2.2.3 lib/locomotive/action_controller/locale_helpers.rb