Easiest localization of Rails 2.2.2

Here is a common use case: localize all built-in strings and date formats of a Rails application in just one language. I don’t need to switch dynamically, everything should just change to my own language. In my case, Dutch. Here is how I do it with as many built-in things as possible.

Step 1

Make sure you are running Rails version 2.2.2 or higher.

Step 2

Set the default locale in an initializer. Create a new file called config/initializers/default_locale.rb and put this in it:

I18n.default_locale = 'nl'

Of course, use any locale you wish.

Step 3

Install the localized_dates plugin. This will make sure all your dates are formatted according to your locale.

ruby script/plugin install git://github.com/clemens/localized_dates.git

Optional: step 4

Customize the locale file copied to config/locales or grab a new one from Sven’s github. I use a modified version of the Dutch locale since our month names should be lowercase.

About joost

Senior Ruby on Rails web developer, with a focus on content and media management. I have built, and continue to maintain, some of the busiest sites in The Netherlands. I strongly advocate a pleasant and concise user experience, agile development, web standards and open source software.