Sha256: c9941e67fa224cbdd54b8ea8f21dc2ad4ed7ef80f8e1de68981502f3bf8efe4e

Contents?: true

Size: 951 Bytes

Versions: 1

Compression:

Stored size: 951 Bytes

Contents

module Locomotive::Steam
  class Server

    # Set the locale from the path if possible or use the default one
    # Examples:
    #   /fr/index   => locale = :fr
    #   /fr/        => locale = :fr
    #   /index      => locale = :en (default one)
    #
    class Locale < Middleware

      def call(env)
        self.set_accessors(env)

        self.set_locale!(env)

        app.call(env)
      end

      protected

      def set_locale!(env)
        locale  = self.mounting_point.default_locale

        if self.path =~ /^(#{self.mounting_point.locales.join('|')})+(\/|$)/
          locale    = $1
          self.path = self.path.gsub($1 + $2, '')
          self.path = 'index' if self.path.blank?
        end

        Locomotive::Mounter.locale = locale
        ::I18n.locale = locale

        self.log "Detecting locale #{locale.upcase}"

        env['steam.locale'] = locale
        env['steam.path']   = self.path
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
locomotivecms_steam-0.1.0 lib/locomotive/steam/server/locale.rb