Skip to content
kwi edited this page Sep 14, 2010 · 21 revisions

I18n_routing

I18n_routing is a plugin for Ruby on Rails that lets you easily translate your routes trough the I18n api included in Rails since version 2.2

Why translating routes ?

  • A must have if your Rails website is localized.
  • More friendly for your visitors.
  • Url are a key point for SEO, place keywords in them !

I18n_routing keypoints

  • No translations are made during runtime, all is precompiled when building routes at startup.
  • Works with Rails 2.x series (> 2.2) and with Rails 3
  • Builded on top of I18n api => translating your routes as never been as simple as now

Example (Rails 3)

First, declare a localized resources in your routes.rb :

localized do
  resources :users
end

Then, translate your resources in your locales files (if you are using the simple Backend, or anywhere else depending on your I18n backend):

fr:
  resources:
    users: 'utilisateurs'

After that, when you will use any users route helpers in your app, it will transparently use the correct route path depending on your current locale.

$ rails console
ruby-1.8.7-p249 > I18n.locale = :en
 => :en 
ruby-1.8.7-p249 > app.users_path
 => "/users" 
ruby-1.8.7-p249 > I18n.locale = :fr
 => :fr 
ruby-1.8.7-p249 > app.users_path
 => "/utilisateurs" 
ruby-1.8.7-p249 > 
Clone this wiki locally