Module: RouteTranslator::Translator

Defined in:
lib/route_translator/translator.rb,
lib/route_translator/translator/path.rb,
lib/route_translator/translator/path/segment.rb,
lib/route_translator/translator/route_helpers.rb

Defined Under Namespace

Modules: Path, RouteHelpers

Class Method Summary collapse

Class Method Details

.available_localesObject



56
57
58
59
60
61
62
63
# File 'lib/route_translator/translator.rb', line 56

def available_locales
  locales = RouteTranslator.available_locales
  # Make sure the default locale is translated in last place to avoid
  # problems with wildcards when default locale is omitted in paths. The
  # default routes will catch all paths like wildcard if it is translated first.
  locales.delete I18n.default_locale
  locales.push I18n.default_locale
end

.route_name_for(args, old_name, suffix, kaller) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/route_translator/translator.rb', line 80

def route_name_for(args, old_name, suffix, kaller)
  args_locale         = locale_from_args(args)
  current_locale_name = I18n.locale.to_s.underscore

  locale = if args_locale
             args_locale.to_s.underscore
           elsif kaller.respond_to?(:"#{old_name}_#{current_locale_name}_#{suffix}")
             current_locale_name
           else
             I18n.default_locale.to_s.underscore
           end

  "#{old_name}_#{locale}_#{suffix}"
end

.translations_for(route) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/route_translator/translator.rb', line 65

def translations_for(route)
  RouteTranslator::Translator::RouteHelpers.add route.name, route.route_set.named_routes

  available_locales.each do |locale|
    translated_path = translate_path(route.path, locale, route.scope)
    next unless translated_path

    translated_name                = translate_name(route.name, locale, route.route_set.named_routes.names)
    translated_options_constraints = translate_options_constraints(route.options_constraints, locale)
    translated_options             = translate_options(route.options, locale)

    yield locale, translated_name, translated_path, translated_options_constraints, translated_options
  end
end