Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Closing bug #12

  • Loading branch information...
commit ceca75428a43b4f4bb2551c127187fb1a5467828 1 parent 49d2e76
@raul authored
Showing with 19 additions and 7 deletions.
  1. +6 −5 lib/route_translator.rb
  2. +13 −2 test/translate_routes_test.rb
View
11 lib/route_translator.rb
@@ -151,6 +151,7 @@ def translate route_set
# save original routes and clear route set
original_routes = route_set.routes.dup # Array [routeA, routeB, ...]
+
original_named_routes = route_set.named_routes.routes.dup # Hash {:name => :route}
reset_route_set route_set
@@ -237,12 +238,12 @@ def translate_path path, locale
segments.join "/"
end
- if add_prefix? locale
- new_path = "/:#{LOCALE_PARAM_KEY}" + new_path
- end
- return "/" if new_path.blank?
+ new_path = "/#{locale}#{new_path}" if add_prefix? locale
+ # if add_prefix? locale
+ # new_path = "/:#{LOCALE_PARAM_KEY}" + new_path
+ # end
- new_path
+ new_path.blank? ? '/' : new_path
end
# Tries to translate a single path segment. If the path segment
View
15 test/translate_routes_test.rb
@@ -162,8 +162,7 @@ def test_named_root_route_with_prefix
@route_translator.load_dictionary_from_file File.expand_path('locales/routes.yml', File.dirname(__FILE__))
translate_routes
- # i think this is the wanted behavior, anyhow, can't get assert_routing to work
- # assert_routing '/', :controller => 'people', :action => 'index'
+ assert_routing '/', :controller => 'people', :action => 'index'
assert_recognizes( {:controller => 'people', :action => 'index'}, '/')
assert_routing '/es', :controller => 'people', :action => 'index', :locale => 'es'
assert_routing '/en', :controller => 'people', :action => 'index', :locale => 'en'
@@ -202,6 +201,18 @@ def test_named_translated_route_on_non_default_locale_with_prefix
assert_helpers_include :people_en, :people_es, :people
end
+ def test_named_translated_route_with_prefix_must_have_locale_as_static_segment
+ @routes.draw { match 'people', :to => 'people#index', :as => 'people' }
+ config_default_locale_settings('en', false)
+ @route_translator.yield_dictionary { |t| t['en'] = {}; t['es'] = {'people' => 'gente'} }
+ translate_routes
+
+ # we check the string representation of the route,
+ # if it stores locale as a dynamic segment it would be represented as: "/:locale/gente"
+ people_es = @routes.routes.select{ |r| r.name == 'people_es' }.first
+ assert_equal "/es/gente", people_es.to_s.split(' ')[1]
+ end
+
# Named routes without prefix on default locale:
def test_named_empty_route_without_prefix
Please sign in to comment.
Something went wrong with that request. Please try again.