Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
44 lines (29 sloc) 1.43 KB

localized_routes

localized_routes is a plugin for Ruby on Rails 3 that makes translating URLs dead simple.

Just install the plugin and add some route translations. Then you're ready to go:

  • URLs have the form /{locale}/…, such as /en/…, /es/…

  • Locale is obtained from the URL as a filter before processing controllers.

  • When building URLs, the current locale is automatically added, so the usage is transparent.

For example, let an app have the following routes:

/
/events
/events/:id/comments

After installing the plugin, the routes can be translated in your locale files like this:

es:
  routes:
    events: eventos
    comments: comentarios

Then, the following routes will be available:

/ (will show home page with default locale)
/en
/es
/en/events
/es/eventos
/en/events/:id/comments
/es/eventos/:id/comentarios

Helper methods such as events_path or event_comments_path still exist, along with events_es_path, event_comments_es_path, events_en_path, and event_comments_en_path. Therefore, the usage is totally transparent.

Routes can be marked as non-i18n-able. E.g.:

match '/captcha/:id', :to => 'captcha#show', :as => :captcha, :i18n=>false

This will prevent creating different routes with the available locales.

Works with Rails 3. Inspired in i18n_routing and translate_routes plugins.

Copyright © 2010 José Ignacio Fernández (joseignacio.fernandez <at> gmail.com). Released under the MIT license.