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



53
54
55
56
57
58
59
60
61
# File 'lib/route_translator/translator.rb', line 53

def available_locales
  locales = RouteTranslator.available_locales
  locales.concat(RouteTranslator.native_locales) if RouteTranslator.native_locales.present?
  # 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



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

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}_native_#{current_locale_name}_#{suffix}")
             "native_#{current_locale_name}"
           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



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

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