Rails 3 plugin to help making localized URLs
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
MIT-LICENSE
README.rdoc
init.rb
localized_routes.gemspec

README.rdoc

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.