Module: RouteTranslator::Host

Included in:
RouteTranslator
Defined in:
lib/route_translator/host.rb

Class Method Summary collapse

Class Method Details

.lambdas_for_locale(locale) ⇒ Object



32
33
34
# File 'lib/route_translator/host.rb', line 32

def lambdas_for_locale(locale)
  lambdas[locale] ||= ->(req) { locale == RouteTranslator::Host.locale_from_host(req.host) }
end

.locale_from_host(host) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/route_translator/host.rb', line 24

def locale_from_host(host)
  available_locales = I18n.available_locales

  RouteTranslator.config.host_locales.find do |pattern, locale|
    available_locales.include?(locale&.to_sym) && host&.match?(regex_for(pattern))
  end&.last&.to_sym
end