Sha256: 5735ad1a497e24f7a6ad67bdb10b6a081dcb47f26547ae8cbea19cc2a9b63c69

Contents?: true

Size: 809 Bytes

Versions: 32

Compression:

Stored size: 809 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 || 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

32 entries across 32 versions & 2 rubygems

Version Path
social_stream-0.23.3 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-base-0.17.2 lib/social_stream/controllers/i18n_integration.rb
social_stream-0.23.2 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-base-0.17.1 lib/social_stream/controllers/i18n_integration.rb
social_stream-0.23.1 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-base-0.17.0 lib/social_stream/controllers/i18n_integration.rb
social_stream-0.22.1 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-base-0.16.4 lib/social_stream/controllers/i18n_integration.rb
social_stream-0.22.0 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-base-0.16.3 lib/social_stream/controllers/i18n_integration.rb
social_stream-0.21.4 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-base-0.16.2 lib/social_stream/controllers/i18n_integration.rb
social_stream-0.21.3 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-0.21.2 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-0.21.1 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-base-0.16.1 lib/social_stream/controllers/i18n_integration.rb
social_stream-0.21.0 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-base-0.16.0 lib/social_stream/controllers/i18n_integration.rb
social_stream-0.20.2 base/lib/social_stream/controllers/i18n_integration.rb
social_stream-base-0.15.2 lib/social_stream/controllers/i18n_integration.rb