Sha256: d3c75d0501eecb0efb3e4c948a83e4e81fc16497b5ed6cc25e1e69ed0b03b7ce

Contents?: true

Size: 737 Bytes

Versions: 4

Compression:

Stored size: 737 Bytes

Contents

module Locomotive
  module Middlewares
    class Locale

      def initialize(app, opts = {})
        @app = app
      end

      def call(env)
        retrieve_and_set_locale(env)
        @app.call(env)
      end

      def retrieve_and_set_locale(env)
        site = env['locomotive.site']

        if site.try(:localized?)
          if env['PATH_INFO'] =~ %r{^/(#{site.locales.join('|')})+(\/|$)}
            locale  = $1
            path    = env['PATH_INFO'].gsub($1 + $2, '').gsub(/(\/_edit|\/_admin)$/, '')

            Locomotive.log "[extract locale] locale = #{locale} / #{path}"

            env['locomotive.locale']  = locale
            env['locomotive.path']    = path
          end
        end
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
locomotive_cms-2.5.7 lib/locomotive/middlewares/locale.rb
locomotive_cms-2.5.6 lib/locomotive/middlewares/locale.rb
locomotive_cms-2.5.6.rc2 lib/locomotive/middlewares/locale.rb
locomotive_cms-2.5.6.rc1 lib/locomotive/middlewares/locale.rb