Sha256: 8e15fbd782ea53c7a0a36c5752431d2d067d7995b31d0869c2cfa0ead1f8cab4
Contents?: true
Size: 1.03 KB
Versions: 27
Compression:
Stored size: 1.03 KB
Contents
module Locomotive::Steam module Middlewares # 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) # # The # class Locale < ThreadSafe include Helpers def _call locale = extract_locale log "Detecting locale #{locale.upcase}" I18n.with_locale(locale) do self.next end end protected def extract_locale _locale = params[:locale] || default_locale _path = request.path_info if _path =~ /^\/(#{site.locales.join('|')})+(\/|$)/ _locale = $1 _path = _path.gsub($1 + $2, '') # let the other middlewares that the locale was # extracted from the path. env['steam.locale_in_path'] = true end env['steam.path'] = _path env['steam.locale'] = services.locale = _locale end end end end
Version data entries
27 entries across 27 versions & 1 rubygems