Sha256: 86980662c9a478bdd0c9ab19c87982e4817da29266c6df92ead45d267fbaa688
Contents?: true
Size: 957 Bytes
Versions: 6
Compression:
Stored size: 957 Bytes
Contents
module Locomotive::Builder 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['builder.locale'] = locale env['builder.path'] = self.path end end end end
Version data entries
6 entries across 6 versions & 1 rubygems