# Add a lang param in routes

**URL:** <https://www.ruby-forum.com/t/add-a-lang-param-in-routes/175777>\
**Category:** Rails\
**Created:** [September 19, 2009, 1:51pm UTC](https://www.ruby-forum.com/t/add-a-lang-param-in-routes/175777 "2009-09-19T13:51:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dddennisdennis734](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a88e57/32.png) [@dddennisdennis734](https://www.ruby-forum.com/u/dddennisdennis734)\
**Post date:** [September 19, 2009, 1:51pm UTC](https://www.ruby-forum.com/t/add-a-lang-param-in-routes/175777/1 "2009-09-19T13:51:13Z")

</div>

Hi,

What kind of edition can we do to add a language parameter in thoses  
routes:

ActionController::Routing::Routes.draw do |map|  
map.resource :user\_session  
map.resources :users  
map.resources :posts, :has\_many =\> :comments  
end

For example, if the current language is english,  
[http://localhost:3000/posts](http://localhost:3000/posts)

should become:  
[http://localhost:3000/en/posts](http://localhost:3000/en/posts)

And  
[http://localhost:3000/posts/1/comments/1](http://localhost:3000/posts/1/comments/1)

should become:  
[http://localhost:3000/en/posts/1/comments/1](http://localhost:3000/en/posts/1/comments/1)

If possible, this new parameter should not modify my current paths, such  
as posts\_path.

Thanks for any ideas!

Denis

---

<div class="post-metadata">

**Author:** ![dddennisdennis734](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a88e57/32.png) [@dddennisdennis734](https://www.ruby-forum.com/u/dddennisdennis734)\
**Post date:** [September 19, 2009, 10:59pm UTC](https://www.ruby-forum.com/t/add-a-lang-param-in-routes/175777/2 "2009-09-19T22:59:34Z")

</div>

In case you haven’t read this yet:

> **[Rails Internationalization (I18n) API — Ruby on Rails Guides](https://guides.rubyonrails.org/i18n.html)**
>
> Rails Internationalization (I18n) APIThe Ruby I18n (shorthand for internationalization) gem which is shipped with Ruby on Rails (starting from Rails 2.2) provides an easy-to-use and extensible framework for translating your application to a single...

Tom

---

<div class="post-metadata">

**Author:** ![dddennisdennis734](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a88e57/32.png) [@dddennisdennis734](https://www.ruby-forum.com/u/dddennisdennis734)\
**Post date:** [September 21, 2009, 8:02am UTC](https://www.ruby-forum.com/t/add-a-lang-param-in-routes/175777/3 "2009-09-21T08:02:50Z")

</div>

(Shameless self-promotion) You can also use my translate\_routes plugin:

[GitHub - raul/translate\_routes: Rails plugin to translate your URLs and routing helpers on an clean way.](http://github.com/raul/translate_routes/)

which not only adds a locale parameter and prefix:

[http://localhost:3000/en/articles/1/comments/1](http://localhost:3000/en/articles/1/comments/1)  
[http://localhost:3000/es/articulos/1/comentarios/1](http://localhost:3000/es/articulos/1/comentarios/1)

But also allows you to translate the static fragments of your routes,  
improving your SEO performance. Your current xxxxx\_path and xxxxx\_url  
helpers will be transparently converted to the current request’s  
locale, so you just need to add a .yml translations file and one line  
to your config/routes.rb.

Hope it helps!

–  
Raul M. - Freelance Web D.  
[http://raul.murciano.net](http://raul.murciano.net)

On Sat, Sep 19, 2009 at 1:51 PM, Denis D.
