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



28
29
30
# File 'lib/route_translator/host.rb', line 28

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

.locale_from_host(host) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/route_translator/host.rb', line 20

def locale_from_host(host)
  available_locales = I18n.available_locales

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