Search code examples
ruby-on-railslocalizationtranslationglobalize2

Rails 2.2 translation plugin/gem


I'm looking for a localisation system to use in a rails 2.2.2 app that i manage. I think i've seen one before that does exactly what i want but i can't manage to find it with google.

The system i have in mind works as follows: any ActiveRecord model (or perhaps a list of specified models, listed in a config file for example) can have a translation record associated with it, which specifies a locale and the new values for one or more of the fields in that record, for the listed locale. Please note this is a seperate sort of problem to that solved by i18n: it's a way of setting locale-specific data, rather than locale-specific names of fields or similar "system-level" strings.

For example, let's say my site provides music lessons. In the UK (the default locale), musical notes which last one "beat" are called "crotchets"* while in the US they're called "quarter notes". So, i might have a lesson that has this data:

#a Lesson object, with an entry in the "lessons" table in the db
id: 1234
name: "My Lesson"
description: "In this lesson you'll learn about crotchets."

and I want this translation record associated with it:

id: 1
translatable_type: "Lesson"
translatable_id: 1234
locale: "US"
data: {:description => "In this lesson you'll learn about quarter notes"}

Now, when i view the lesson, the system checks the current locale, and sees if there's any current-locale-specific data for this lesson, sees that there is (the description) and displays that instead of the standard description.

Has anyone seen a system like this?

thanks, max

PS - in this example i've done a simple string substitution of "crotchets" to "quarter notes", which might tempt the reader to think i just need some kind of simple string substitution translation. But that's not the case - some of the US-specific names/descriptions will be quite different to their uk counterparts and so require a completely customisable us-facing name, description, etc.

*this might not be exactly musically true in all cases but that's outside the scope of this question :)


Solution

  • I think that Globalize2 may be what you are after for locale-specific data solutions (I've had success using Globalize3 for my Rails 3.2 apps). If not, then hopefully the alternative solutions section on Globalize2's Github repo README file will provide something else that will work for you with Rails 2.2. Good luck!