# Language code in the URL

**URL:** <https://www.ruby-forum.com/t/language-code-in-the-url/113185>\
**Category:** Rails I18n\
**Created:** [August 28, 2007, 2:29pm UTC](https://www.ruby-forum.com/t/language-code-in-the-url/113185 "2007-08-28T14:29:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![steerio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/919ad9/32.png) [@steerio](https://www.ruby-forum.com/u/steerio)\
**Post date:** [August 28, 2007, 2:29pm UTC](https://www.ruby-forum.com/t/language-code-in-the-url/113185/1 "2007-08-28T14:29:56Z")

</div>

Cheers fellow developers,

in our application we would like to include a language code in the URL’s  
of at least some resources, mainly for SEO reasons (Google should index  
several language versions of the same page so users can find them). Our  
ultimate choice for a scheme looks like this:

/foobars/123.en.html  
/foobars/123.fr.html

This displays neatly what it’s all about: in contrast with a choice like  
/en/foobars/123.html it correctly suggests that these URL’s are not  
pointing to entirely different kinds of resources but variants of the  
same one. It also _seems_ to be easier to achieve by a generic, DRY  
solution.

My question is: _is this somehow possible without major tweakings in  
Rails internals?_ I’d also note that we would like to avoid external  
rewriting for obvious portability reasons.

---

<div class="post-metadata">

**Author:** ![steerio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/919ad9/32.png) [@steerio](https://www.ruby-forum.com/u/steerio)\
**Post date:** [August 28, 2007, 3:51pm UTC](https://www.ruby-forum.com/t/language-code-in-the-url/113185/2 "2007-08-28T15:51:23Z")

</div>

Hey …

> /foobars/123.en.html  
> /foobars/123.fr.html

> My question is: _is this somehow possible without major tweakings in  
> Rails internals?_ I’d also note that we would like to avoid external  
> rewriting for obvious portability reasons.

thats exactly a topic of a talk at the next rails conference in  
berlin later this year 😉

yes it is possible, but not without some serious tweaking.  
especially if you want to be RESTful. Basically you need to  
extend the routed to not only support :format, but :locale.:format.

I’m actually working on that right now, but it’s far from stable.  
I hope to release this as a plugin in the future, you can get  
a first glimpse at it right here:

[http://bugs.omdb.org/browser/branches/2007.1/vendor/plugins/mlcache/](http://bugs.omdb.org/browser/branches/2007.1/vendor/plugins/mlcache/)  
lib/actionpack\_ext.rb

this will support extensions to RESTful routes, as well as updated  
page and fragment caching to respect the locale set for  
the current request.

Ben
