# Multiple language routes - is that possible?

**URL:** <https://www.ruby-forum.com/t/multiple-language-routes-is-that-possible/86466>\
**Category:** Rails\
**Created:** [February 22, 2007, 3:02pm UTC](https://www.ruby-forum.com/t/multiple-language-routes-is-that-possible/86466 "2007-02-22T15:02:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmihelac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5fc32e/32.png) [@bmihelac](https://www.ruby-forum.com/u/bmihelac)\
**Post date:** [February 22, 2007, 3:02pm UTC](https://www.ruby-forum.com/t/multiple-language-routes-is-that-possible/86466/1 "2007-02-22T15:02:38Z")

</div>

Hello all,  
does anyone have experience with routing in multi language applications

- I would like to create routes preserving meaning in original language  
in URL. Something like these:  
/en/cities/158  
/it/citta/158

Writing one route for every controller and language is not desired as  
these can mean handling hundreds of routes. It also creates problem with  
named routes.

Also, when is controller loaded and executed - can app influence on that  
apart from defining routes? Would it be possible to load some generic  
controller which will load some specific controller?

thanks in advance for answer or opinion,  
Bojan M.

–  
Bojan M.  
Informatika Mihelac, Bojan M. s.p. | [www.informatikamihelac.com](http://www.informatikamihelac.com)  
 → tools, scripts, tricks from our code lab: [http://source.mihelac.org](http://source.mihelac.org)

---

<div class="post-metadata">

**Author:** ![bmihelac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5fc32e/32.png) [@bmihelac](https://www.ruby-forum.com/u/bmihelac)\
**Post date:** [February 25, 2007, 6:10pm UTC](https://www.ruby-forum.com/t/multiple-language-routes-is-that-possible/86466/2 "2007-02-25T18:10:20Z")

</div>

I had an idea about this that might help you. Hopefully. Presuming  
you’re  
serving up a finite set of languages, perhaps something like

map.city “/:lang/:city\_var/:id”, :controller =\> X, :action =\> Y,  
:city\_var  
=\> /cities|citta|ciudades/

I don’t know you could enforce a matchup between, say, “en” and “cities”  
or  
“it” and “citta” but it might be doable. If that’s not an issue then I’d  
think this would work okay. Anyone see problems with it?

RSL

---

<div class="post-metadata">

**Author:** ![bmihelac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5fc32e/32.png) [@bmihelac](https://www.ruby-forum.com/u/bmihelac)\
**Post date:** [February 25, 2007, 9:34pm UTC](https://www.ruby-forum.com/t/multiple-language-routes-is-that-possible/86466/3 "2007-02-25T21:34:12Z")

</div>

I am currently using this aproach but it is not elegant because:

- en/ciudades url and all other combinations would exist, which is minor  
problem and

- generating url’s with that kind of route is problematic, for example  
city\_url(:lang =\> ‘it’, :id =\> 122) would yield nothing as :city\_var is  
not set, and on the other side to set proper :city\_var in view I need to  
know exact translation which means having some translation table,  
probably in database… and that mean that it would be better to make  
routes.rb look in the database and create routes dynamically, i am  
moving in circle here…

best regards,  
Bojan M.

Russell N. wrote:

> RSL  
> /it/citta/158  
> thanks in advance for answer or opinion,
> 
> >

–  
Bojan M.  
Informatika Mihelac, Bojan M. s.p. | [www.informatikamihelac.com](http://www.informatikamihelac.com)  
 → tools, scripts, tricks from our code lab: [http://source.mihelac.org](http://source.mihelac.org)

---

<div class="post-metadata">

**Author:** ![bmihelac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5fc32e/32.png) [@bmihelac](https://www.ruby-forum.com/u/bmihelac)\
**Post date:** [February 25, 2007, 9:54pm UTC](https://www.ruby-forum.com/t/multiple-language-routes-is-that-possible/86466/4 "2007-02-25T21:54:14Z")

</div>

> > ```
> > does anyone have experience with routing in multi language
> > applications - I would like to create routes preserving meaning in
> > original language in URL. Something like these:
> > /en/cities/158
> > /it/citta/158
> > 
> > ```

The HTTP standard was specifically written with the concept of  
“alternatives” in mind, outside of the URL. In particualr, web browsers  
are  
suppsoed to send an “Accept-Language” header which explains what  
language  
the end user is most familiar with.

This can be problematic for people who are browsing on someone else’s  
machine, etc, so there should also be some sort of mechanism for the end  
user to set their language - I’d suggest setting a cookie - but the  
“Accept-Language” header should be used to determine the default  
language if  
the user has not yet selected one.

There appears to be a “Globalize” plugin for ruby on rails that  
handles a  
lot of this:

[http://wiki.globalize-rails.org/globalize/](http://wiki.globalize-rails.org/globalize/)

I haven’t used it (yet), so I don’t know how well it works, but  
browsing  
through the examples, etc, it looks like a lot of thought has gone into  
it!

- Tyler
