Module: RouteTranslator::Host

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.locale_from_host(host) ⇒ Object



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

def locale_from_host(host)
  locales = RouteTranslator.config.host_locales.each_with_object([]) do |(pattern, locale), result|
    result << locale.to_sym if host =~ regex_for(pattern)
  end
  locales &= I18n.available_locales
  (locales.first || I18n.default_locale).to_sym
end

Instance Method Details

#native_locale?(locale) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/route_translator/host.rb', line 12

def native_locale?(locale)
  locale.to_s.match(/native_/).present?
end

#native_localesObject



16
17
18
# File 'lib/route_translator/host.rb', line 16

def native_locales
  config.host_locales.values.map { |locale| :"native_#{locale}" }
end