Sha256: af17ea48f08a8a05fb28555aa3c1faaeea2b6a596173baf96bef92ac90f3e082
Contents?: true
Size: 951 Bytes
Versions: 22
Compression:
Stored size: 951 Bytes
Contents
module Locomotive::Wagon 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['wagon.locale'] = locale env['wagon.path'] = self.path end end end end
Version data entries
22 entries across 22 versions & 1 rubygems