Sha256: 360adea98f5aac44d85b009b7ba63f2f180294c9329c9c82b1f21d955518bbd2

Contents?: true

Size: 829 Bytes

Versions: 91

Compression:

Stored size: 829 Bytes

Contents

module SocialStream
  module Controllers
    # Common methods added to ApplicationController
    module I18nIntegration
      extend ActiveSupport::Concern

      included do
         before_filter :set_locale
      end

      # Set locale as per params, user preference or default
      def set_locale
        I18n.locale = params[:locale] || user_preferred_locale || session[:locale] || extract_locale_from_accept_language_header || I18n.default_locale
      end

      private
      def extract_locale_from_accept_language_header
        return nil if request.env['HTTP_ACCEPT_LANGUAGE'].nil?
        (request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).map{|l| l.to_sym} & I18n.available_locales).first
      end

      def user_preferred_locale
        current_user.language if user_signed_in?
      end
    end
  end
end

Version data entries

91 entries across 91 versions & 2 rubygems

Version Path
social_stream-2.2.2 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-base-2.2.2 lib/social_stream/controllers/i18n_integration.rb
social_stream-2.2.1 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-base-2.2.1 lib/social_stream/controllers/i18n_integration.rb
social_stream-2.2.0 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-base-2.2.0 lib/social_stream/controllers/i18n_integration.rb
social_stream-2.1.1 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-1.1.12 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-base-1.1.11 lib/social_stream/controllers/i18n_integration.rb
social_stream-2.1.0 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-base-2.1.0 lib/social_stream/controllers/i18n_integration.rb
social_stream-2.0.4 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-base-2.0.4 lib/social_stream/controllers/i18n_integration.rb
social_stream-2.0.3 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-base-2.0.3 lib/social_stream/controllers/i18n_integration.rb
social_stream-1.1.11 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-base-1.1.10 lib/social_stream/controllers/i18n_integration.rb
social_stream-1.1.10 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-base-1.1.9 lib/social_stream/controllers/i18n_integration.rb
social_stream-1.1.9 base/lib/social_stream/controllers/i18n_integration.rb