# Routing: Language as first part of path, for just about everything

**URL:** <https://www.ruby-forum.com/t/routing-language-as-first-part-of-path-for-just-about-everything/135947>\
**Category:** Rails\
**Created:** [April 26, 2008, 8:04pm UTC](https://www.ruby-forum.com/t/routing-language-as-first-part-of-path-for-just-about-everything/135947 "2008-04-26T20:04:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MRoderick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8dc957/32.png) [@MRoderick](https://www.ruby-forum.com/u/MRoderick)\
**Post date:** [April 26, 2008, 8:04pm UTC](https://www.ruby-forum.com/t/routing-language-as-first-part-of-path-for-just-about-everything/135947/1 "2008-04-26T20:04:12Z")

</div>

Hi Group

Like others before me have posted to the group, I am trying to  
implement routes that have language as the first part of the path,  
without having to rewrite just about every url generating statement  
across the codebase (my own, plugins, tests, etc).

Let’s start with an example:

map.login ‘/:lang/login’, :controller =\> ‘sessions’, :action =\> ‘new’  
map.resources :categories, :path\_prefix =\> ‘:lang’

Having looked around, I managed to find two plugins, that get’s me  
half-way there:

[http://www.artweb-design.de/2007/5/13/concise-localized-rails-url-helpers-solved-twice](http://www.artweb-design.de/2007/5/13/concise-localized-rails-url-helpers-solved-twice)

More specifically resource\_fu and localized\_url\_helpers

Adding either of these and setting a default language in  
default\_url\_options, it’s easy to get a nice default value for named  
routes

def default\_url\_options(options)  
{ :lang =\> ‘en’ }  
end

But, what do I do with non-named routes?

link\_to :controller =\> ‘categories’, :action =\> ‘index’  
won’t work, as it won’t have the lang parameter specified  
automagically.

Something tells me that I am looking at this from a “less-than-  
optimal” angle, so any advice is welcome

/Morgan
