Module: RouteTranslator

Extended by:
Host
Defined in:
lib/route_translator.rb,
lib/route_translator/host.rb,
lib/route_translator/route.rb,
lib/route_translator/version.rb,
lib/route_translator/translator.rb,
lib/route_translator/translator/path.rb,
lib/route_translator/extensions/test_case.rb,
lib/route_translator/translator/path/segment.rb,
lib/route_translator/translator/route_helpers.rb,
lib/generators/route_translator/install_generator.rb,
lib/route_translator/extensions/action_controller.rb

Defined Under Namespace

Modules: Controller, Generators, Host, TestCase, Translator Classes: Configuration, Route

Constant Summary collapse

TRANSLATABLE_SEGMENT =
/^([-_a-zA-Z0-9]+)(\()?/.freeze
DEFAULT_CONFIGURATION =
{
  available_locales:                   [],
  disable_fallback:                    false,
  force_locale:                        false,
  generate_unlocalized_routes:         false,
  generate_unnamed_unlocalized_routes: false,
  hide_locale:                         false,
  host_locales:                        {},
  locale_param_key:                    :locale,
  locale_segment_proc:                 false
}.freeze
VERSION =
'14.2.0'

Class Method Summary collapse

Methods included from Host

lambdas_for_locale, locale_from_host

Class Method Details

.available_localesObject



65
66
67
68
69
70
71
72
73
# File 'lib/route_translator.rb', line 65

def available_locales
  locales = config.available_locales

  if locales.empty?
    I18n.available_locales.dup
  else
    locales.map(&:to_sym)
  end
end

.config {|@config| ... } ⇒ Object

Yields:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/route_translator.rb', line 44

def config
  @config ||= Configuration.new

  DEFAULT_CONFIGURATION.each do |option, value|
    @config[option] ||= value
  end

  yield @config if block_given?

  resolve_host_locale_config_conflicts if @config.host_locales.present?
  check_deprecations

  @config
end

.deprecatorObject



84
85
86
# File 'lib/route_translator.rb', line 84

def deprecator
  @deprecator ||= ActiveSupport::Deprecation.new(RouteTranslator::VERSION, 'RouteTranslator')
end

.locale_from_params(params) ⇒ Object



79
80
81
82
# File 'lib/route_translator.rb', line 79

def locale_from_params(params)
  locale = params[config.locale_param_key]&.to_sym
  locale if I18n.available_locales.include?(locale)
end

.locale_param_keyObject



75
76
77
# File 'lib/route_translator.rb', line 75

def locale_param_key
  config.locale_param_key
end

.reset_configObject



59
60
61
62
63
# File 'lib/route_translator.rb', line 59

def reset_config
  @config = nil

  config
end