Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

made base_url_helpers work with fully qualified locales

  • Loading branch information...
commit dfaa6dd48acacf9e11725acf757024e39251b2b8 1 parent 472b8a9
Erik Ogan and Thomas Shafer authored erikogan committed
View
10 lib/i18n_routable/mapper/localizable_route.rb
@@ -2,6 +2,10 @@ module I18nRoutable
module Mapper
module LocalizableRoute
+ def self.normalize_locale locale
+ locale.to_s.downcase.gsub /-/, '_'
+ end
+
private
def translate_route en_route
@@ -40,11 +44,7 @@ def translated_defaults en_defaults, locale
end
def translated_name en_name, locale
- "#{normalize_locale locale}_#{en_name}"
- end
-
- def normalize_locale locale
- locale.to_s.downcase.gsub /-/, '_'
+ "#{I18nRoutable::Mapper::LocalizableRoute.normalize_locale locale}_#{en_name}"
end
end
View
1  lib/i18n_routable/route_set/localizable_url_helper.rb
@@ -32,6 +32,7 @@ def #{selector}_with_localize(options={})
locale, args = I18nRoutable::RouteSet::LocalizableUrlHelper.extract_locale!([options])
#{selector}_without_localize(*args).tap do |hsh|
if locale && #{locales.inspect}.include?(locale)
+ locale = I18nRoutable::Mapper::LocalizableRoute.normalize_locale(locale)
hsh[:use_route] = "\#\{locale\}_#{name}"
end
end
View
3  spec/i18n_routable/i18n_routable_spec.rb
@@ -31,6 +31,7 @@ def base_named_route_for(options)
it 'should route a localized path properly' do
resolve("/es/puestos").should == { :action => "index", :controller => "posts", :locale => "es" }
+ resolve("/fr-CA/canada_test").should == { :action => "foo", :controller => "test", :locale => "fr-CA" }
end
it 'should not route an unlocalized path properly' do
@@ -91,6 +92,7 @@ def base_named_route_for(options)
it "should create named routes with locale prefixes" do
es_posts_path.should == "/es/puestos"
fr_new_event_path.should == "/fr/evenements/nouvelles"
+ fr_ca_new_event_path.should == "/fr-CA/evenements/nouvelles"
end
it "should create named routes without locale prefixes when specified" do
@@ -109,6 +111,7 @@ def base_named_route_for(options)
it "should accept :locale param as an option" do
posts_path(:locale => :es).should == "/es/puestos"
+ posts_path(:locale => :'fr-CA').should == "/fr-CA/messages"
posts_path(:locale => I18n.default_locale).should == posts_path
I18n.locale = :es
posts_path(:locale => :en).should == "/posts" # option overrides I18n.locale
View
2  spec/locales/routes.yml
@@ -29,4 +29,4 @@ fr-CA:
users: utilisateurs
posts: messages
comments: commentaires
- test: test
+ test: canada_test
Please sign in to comment.
Something went wrong with that request. Please try again.