Forum: Rails I18n I18n in Rails 3

Posted by Albert Llop (mrsimo)
on 2010-03-04 21:35
(Received via mailing list)
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 Llop" }
Posted by Kristian Mandrup (Guest)
on 2010-03-05 17:17
(Received via mailing list)
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
Posted by Michael Voigt (Guest)
on 2010-03-05 23:39
(Received via mailing list)
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 Voigt Herbert-Weichmann-Str. 35 22085 Hamburg Germany

2010/3/4 Albert Llop <mrsimo@gmail.com>:
Posted by micha.voigt (Guest)
on 2010-03-05 23:41
(Received via mailing list)
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 Voigt Herbert-Weichmann-Str. 35 22085 Hamburg Germany
Posted by Albert Llop (mrsimo)
on 2010-03-06 00:46
(Received via mailing list)
Thanks a lot!
scope should do the trick.

awesome!
--
{ :name => "Albert Llop" }
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.