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 Mihelac
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?
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...
> 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: