Permalink
Browse files

Static segments (based in locales and translations) are all downcased.

  • Loading branch information...
1 parent 2cbcf8a commit 4a7c7b9dff072128a4e67f5f1123463f7559bbb6 @raul committed Dec 28, 2010
Showing with 17 additions and 2 deletions.
  1. +2 −2 lib/route_translator.rb
  2. +15 −0 test/translate_routes_test.rb
@@ -222,7 +222,7 @@ def translate_path path, locale
final_optional_segments = path.match(/(\(.+\))$/)[1] rescue nil # i.e: (.:format)
path_segments = path.gsub(final_optional_segments,'').split("/")
new_path = path_segments.map{ |seg| translate_path_segment(seg, locale) }.join('/')
- new_path = "/#{locale}#{new_path}" if add_prefix? locale
+ new_path = "/#{locale.downcase}#{new_path}" if add_prefix? locale
new_path = '/' if new_path.blank?
final_optional_segments ? new_path + final_optional_segments : new_path
end
@@ -237,7 +237,7 @@ def translate_path_segment segment, locale
match = TRANSLATABLE_SEGMENT.match(segment)[1] rescue nil
- translate_string(match, locale) || segment
+ (translate_string(match, locale) || segment).downcase
end
def translate_string str, locale
@@ -157,6 +157,21 @@ def test_formatted_root_route
assert_equal '/es(.:format)', path_string(named_route('root_es'))
end
+ def test_routes_translations_are_always_downcased
+ @routes.draw { match 'people', :to => 'people#index', :as => 'people'}
+ config_default_locale_settings 'en'
+ @route_translator.yield_dictionary { |t| t['en'] = {}; t['es'] = {'people' => 'Gente'} }
+ translate_routes
+ assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
+ end
+
+ def test_routes_locale_prefixes_are_always_downcased
+ @routes.draw { match 'people', :to => 'people#index', :as => 'people'}
+ config_default_locale_settings 'en'
+ @route_translator.yield_dictionary { |t| t['en'] = {}; t['ES'] = {'people' => 'Gente'} }
+ translate_routes
+ assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'ES'
+ end
def test_languages_load_from_file
@routes.draw { match 'people', :to => 'people#index', :as => 'people'}

0 comments on commit 4a7c7b9

Please sign in to comment.