zargony.com

#![desc = "Random thoughts of a software engineer"]

A Rails plugin to use core translations

If you're writing an i18n-enabled Rails application, you have to deal with the translation of your own application as well as with the translation of several Rails core strings (like validation error messages, date formats, and so on). You usually don't need to translate the Rails core strings yourself, since there's a big repository of user-contributed core translations you can pull into your application. However keeping this translations up to date in your application can quickly become cumbersome.

For this reason, I refactored the rails-i18n repository a while ago and made it a Rails plugin. You could install the plugin to your application and it provided Rails core translations for you. Unfortunately it became annoying to keep the fork up to date with the latest translation changes since every rebase or merge was a pain because of the moved file locations.

So my latest solution is another small plugin called rails-i18n-updater, which does not contain the translations itself but downloads them from the above mentioned repository of core translations.

Installing the plugin

Installation of the new plugin works as usual:

./script/plugin install git://github.com/zargony/rails-i18n-updater.git

In case you used rails-i18n as a plugin, you should remove it:

./script/plugin remove rails-i18n

Updating translations

Whenever you want to update to the latest core translations, simply run

rake i18n:update

This will use git to download the latest translations from rails-i18n and put them to vendor/rails-locales. The plugin then, on startup, loads core translations for locales you used in your application by modifying I18n.load_path. These core translations are prepended to the load path, which means that you get them as default translations that can be overridden in your own translation files. Now, updating to the latest translations is as easy as running rake i18n:update.