Joshua Muheim
Joshua Muheim

Reputation: 13243

Globalize gem: how to keep track of translations?

I want to translate some models in my Rails app using Globalize gem. This seems pretty easy, but I wonder how it's best to keep track of changed texts? So that I don't forget to update all other translations after I changed one of them?

Is there some feature for this already built in? So I can see which fields of my model have changed in the meantime compared to some translation, and then I can do the translations and fix them as done?

Also, when I just fix a typo, I don't want the translation to be seen as "changed".

Upvotes: 0

Views: 487

Answers (1)

Chris Salzberg
Chris Salzberg

Reputation: 27374

Interesting question, I can completely understand the need for this. Unfortunately Globalize is quite a minimal gem, which only handles the storing and retrieving of translations, and nothing else. So to answer your first question: no, there is no feature already built-in to do what you want.

To have some kind of feature to track translation changes you would have to add a layer on top of Globalize which would set a flag on columns that had changed in one language, so the user would know to update them in other languages.

I suppose what you would have to do is assign a new column in your translation table (say post_translations) for each translated attribute with a version number, so if you had columns title and summary, you would have in post_translations:

title
title_version
summary
summary_version

Initially (say) each version column is 1. When updating a single column like table, you would update the version to 2, to indicate that it had been updated from the original translation.

You could then use this discrepancy in versions to force the user to update summary to match the changed language's translation, and once this is done update its version to 2 (same for any other languages).

For typos, you could just not update the version to avoid forcing a sync across languages.

This is a pretty primitive implementation of course. It wouldn't handle the case of two languages updated independently, for example: in this situation both languages would need to be sync'ed to each other. The ultimate complexity in that scenario is similar to the complexity of branching and merging in revision control systems like git. This would require a slightly more sophisticated versioning scheme.

Even so, the basic problem is quite interesting, and even a minimal solution would be interesting to (say) add as a globalize extension if you went that far. Good luck!

(For the record, I'm one of the authors of Globalize although not very active recently...)

Upvotes: 1

Related Questions