smallroomsoftware.com

Internationalisation with the globalize-rails plugin

Posted on November 02, 2006

I've been using the globalize-rails plugin for translation and localisation of my webapp. I'm fairly happy with with the plugin - it makes a good attempt to globalise most aspects of your application including strings in views and strings used anywhere else (uses the same mechanism, a .t method on instances of the String class) and also data in the database. This is the complicated bit - efficiently loading translations when records are loaded using a non-default locale. Seems to work though pretty well though but with two limitations:

  • Doesn't work when you use an :include option on associations or when calling ActiveRecord::Base::find. Instead, an :includetranslated option can be used but that only works with :belongsto associations which seems like the least useful behaviour.
  • Data isn't translated if you used find_by_sql. I guess this isn't really surprising but as my main 'search' function has to use findby_sql I suspect it might cause me some problems. Maybe there is a way to join with the globalizetranslations table and have it load translated attributes when it unmarshals to ActiveRecord objects.

I've created a reasonable UI for translating data:

In my view (say _form.rhtml) I have something like:

<%= text_field 'space_decl', 'name' %>
<%= translation_links 'space_decl', 'name' %>

Here's the helper module. The css just sets the alpha for untranslated languages:

span.flags img {
  margin-right: 4px;
}

span.flags img.todo {
  filter: alpha(opacity=50);
  -moz-opacity: .50;
  opacity: .50;
}
Post a comment
Comment



If you can read this, you don't use a typical webbrowser that plays nice with CSS.
Please do not fill in anything here!



Hosting by site5.com