Passing locales as the leftmost path segment has always been a bit of  
a hassle with Rails Routing.

Although there are a couple of partial solutions [1] all of them have  
some kind of annoying shortcoming, be it that one can not use non- 
named, old-school routes with it or even has to pass lots of  
parameters to url_for in certain cases and none of them gave me the  
flexibility i wanted.

So I came up with a wild hack that wraps around the whole Rails  
routing system instead of trying to solve things from the inside [2]  
(and can actually be used for a variety of other interesting  
purposes). I've now updated this plugin to work with the I18n API and  
added it to a branch in our Globlize2 demo application [3]

The gist: when you have a default locale :en defined it transparently  
changes route recognition and generation so that you get:

http://host.com/foos/1
http://host.com/de/foos/1

The former is generated when the current locale is the default locale.  
The latter is generated when either the current locale is :de or one  
passes the locale as an option to the url_helper like  
foo_path(foo, :locale => :de)

Both urls are recognized without the need to modify the routes. The  
filter just strips the locale from the beginning of the recognized  
path and puts it to the returned params hash, so one can use it in,  
e.g. the ApplicationController.

This is still experimental, but I'd appreciate some feedback,  
especially if there are cases for url generation that do not work  
(Rails routes are probably one of the most arcane and weird parts of  
Rails, so it's pretty likely that I've overlooked something)



[1] 
http://www.artweb-design.de/2007/5/13/concise-localized-rails-url-helpers-solved-twice
[2] http://github.com/svenfuchs/routing-filter
[3] http://github.com/joshmh/globalize2-demo/tree/routing-filter

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"rails-i18n" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rails-i18n?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to