Rails Translate Columns Plugin

Introduction

In a recent project I worked on there was a major requirement for providing translated content in at least one other language. After looking up several of the current offerings, Globalize and GetText, amongst others, I was left feeling that there was something lacking for the data models.

The main problem with the current alternatives is that while they provide excellent functionality for translating application texts, they don’t help much with the models. Globalize provides a few useful helpers which is cool, but still not as scalable or elegant as I would like.

The Rails Translate Columns plugin essentially provides way to transparently use translation models associated with the model your extracting the data from. This effectively allows you to forget about the complications involved with handling multiple languages in your views and controllers, and simply ensure that the current global locale is correct.

Updates

Feb 2008 – Thanks to Javier Ramirez for suggesting a fix for validation skipping when saving records.

19 Sep 2007 – Revision 92 – The code has been tidied up a bit and written so that the “super” call from a class with translated columns will correctly call the plugin’s methods, and not jump directly to ActiveRecord.

This basically means that it is now possible to overwrite the attribute methods in your own class. I discovered that the ruby “super” call will in fact search through a class’s mixins before its ancestors, so translate_columns now generates an anonymous module with the attribute accessors which is included in the class calling translate_columns. (Check out the code itself if you’re interested! Its not to complicated when you see it.)

Download

The latest version ready to be extracted in the vendor/plugin directory can be found here:

http://www.samlown.com/uploads/projects/translate_columns.tar.gz

SVN sources have been removed until further notice due to a server migration. I’ll try and get a Git repository up as soon as possible.

ruby script/plugin install https://ityzen.com/svn/translate_columns/trunk/vendor/plugins/translate_columns

Readme

Check out the README which describes in detail the required setup.

Page last updated by sam 2 days ago