Sha256: 96cefb2701a35ac379fa71fab1cfa3de5caa208b5948c378b0332008ae4fdcb1

Contents?: true

Size: 1.38 KB

Versions: 5

Compression:

Stored size: 1.38 KB

Contents

module Gluttonberg
  module Middleware
    class Locales
      def initialize(app)
        @app = app
      end

      def call(env)
        path = env['PATH_INFO']
        unless path =~ /^#{Gluttonberg::Engine.config.admin_path}/ || path.start_with?("/stylesheets")  || path.start_with?("/javascripts")   || path.start_with?("/images") ||  path.start_with?("/gluttonberg")  || path.start_with?("/assets")  || path.start_with?("/user_asset")
          case Gluttonberg::Engine.config.identify_locale
            when :subdomain
              # return the sub-domain
            when :prefix
              if Gluttonberg.localized?
                locale = path.split('/')[1]
                if locale.blank?
                  result = Gluttonberg::Locale.first_default
                else
                  result = Gluttonberg::Locale.find_by_locale(locale)
                end
              else # take default locale
                result = Gluttonberg::Locale.first_default
                locale = result.slug
              end
              if result
                env['PATH_INFO'].gsub!("/#{locale}", '')
                env['gluttonberg.locale'] = result
                env['GLUTTONBERG.LOCALE_INFO'] = locale
              end
            when :domain
              env['SERVER_NAME']
          end
        end
        @app.call(env)
      end
    end # Locales
  end # Middleware
end # Gluttonberg

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gluttonberg-core-2.6.4 lib/gluttonberg/middleware/locales.rb
gluttonberg-core-2.6.3 lib/gluttonberg/middleware/locales.rb
gluttonberg-core-2.6.2 lib/gluttonberg/middleware/locales.rb
gluttonberg-core-2.6.1 lib/gluttonberg/middleware/locales.rb
gluttonberg-core-2.6.0 lib/gluttonberg/middleware/locales.rb