# I18n in Rails 3

**URL:** <https://www.ruby-forum.com/t/i18n-in-rails-3/184583>\
**Category:** Rails I18n\
**Created:** [March 4, 2010, 9:35pm UTC](https://www.ruby-forum.com/t/i18n-in-rails-3/184583 "2010-03-04T21:35:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![albert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@albert](https://www.ruby-forum.com/u/albert)\
**Post date:** [March 4, 2010, 9:35pm UTC](https://www.ruby-forum.com/t/i18n-in-rails-3/184583/1 "2010-03-04T21:35:16Z")

</div>

Hi,  
been doing some tiny app in Rails 3 to get the hang of it. From the  
official  
guide currently I don’t know how to do the routes trick:

map.resources :books, :path\_prefix =\> ‘/:locale’

It’s probably me but I can’t find proper rails 3 documentation anywhere.  
Anyone got a link? Didn’t find any more doc on the new router than  
what’s on  
the routes.rb in a new app.

## Thanks!

{ :name =\> “Albert L.” }

---

<div class="post-metadata">

**Author:** ![albert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@albert](https://www.ruby-forum.com/u/albert)\
**Post date:** [March 5, 2010, 5:17pm UTC](https://www.ruby-forum.com/t/i18n-in-rails-3/184583/2 "2010-03-05T17:17:09Z")

</div>

I think you also have to add the :localize argument to all your  
generated paths, fx book\_path(book, :localize =\> ‘de’)  
Personally I think this approach is a bit crazy, must be an easier  
option. Check out my post on this for a solution

* * *

module ActionController::PolymorphicRoutes  
…

def polymorphic\_url  
…

# add default locale from session (retrieved from prefix on route

path)  
args \<\< {:locale =\> session[:locale]} if session[:locale]  
**send** (named\_route, \*args)  
end

---

<div class="post-metadata">

**Author:** ![albert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@albert](https://www.ruby-forum.com/u/albert)\
**Post date:** [March 5, 2010, 11:39pm UTC](https://www.ruby-forum.com/t/i18n-in-rails-3/184583/3 "2010-03-05T23:39:24Z")

</div>

Hi,

the option :path\_prefix is in rails 3 deprecated an will remove in rails  
3.1.

Please use this in you routes.rb:

scope “(/:locale)” do  
resources :items  
end

and in your application controller:

class ApplicationController \< ActionController::Base  
protect\_from\_forgery

before\_filter :set\_locale  
def set\_locale  
I18n.locale = params[:locale]  
end

def default\_url\_options(options={})  
{:locale =\> I18n.locale}  
end  
end

config/application.rb:  
config.i18n.default\_locale = :de

Cheers,  
Michael

– Michael V. Herbert-Weichmann-Str. 35 22085 Hamburg Germany

2010/3/4 Albert L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![albert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@albert](https://www.ruby-forum.com/u/albert)\
**Post date:** [March 5, 2010, 11:41pm UTC](https://www.ruby-forum.com/t/i18n-in-rails-3/184583/4 "2010-03-05T23:41:09Z")

</div>

Hi,

the option :path\_prefix is in rails 3 deprecated an will remove in  
rails  
3.1.

Please use this in you routes.rb:

scope “(/:locale)” do  
resources :items  
end

and in your application controller:

class ApplicationController \< ActionController::Base  
protect\_from\_forgery

before\_filter :set\_locale  
def set\_locale  
I18n.locale = params[:locale]  
end

def default\_url\_options(options={})  
{:locale =\> I18n.locale}  
end  
end

config/application.rb:  
config.i18n.default\_locale = :de

Cheers,  
Michael

– Michael V. Herbert-Weichmann-Str. 35 22085 Hamburg Germany

---

<div class="post-metadata">

**Author:** ![albert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@albert](https://www.ruby-forum.com/u/albert)\
**Post date:** [March 6, 2010, 12:46am UTC](https://www.ruby-forum.com/t/i18n-in-rails-3/184583/5 "2010-03-06T00:46:42Z")

</div>

Thanks a lot!  
scope should do the trick.

## awesome!

{ :name =\> “Albert L.” }
