Sha256: d9b4f5ff684d130ea8dd7eb208c6ffa6347007033b8785075fde0782eb90835a
Contents?: true
Size: 709 Bytes
Versions: 25
Compression:
Stored size: 709 Bytes
Contents
# frozen_string_literal: true module Maglev # Extract the locale from the current HTTP request # and set the Translatable.current_locale accordingly class ExtractLocale include Injectable argument :params argument :locales def call locale, path = extract_locale Maglev::I18n.current_locale = locale params[:path] = path [path, locale] end protected def extract_locale segments = params[:path].split('/') return [default_locale, params[:path]] unless locales.include?(segments[0]&.to_sym) [segments.shift, segments.empty? ? 'index' : segments.join('/')] end def default_locale locales.first end end end
Version data entries
25 entries across 25 versions & 1 rubygems