README.textile

Introduction

I18n translation spawner (ITS) addresses the issue of having to add translation keys to multiple translation files
manually as you develop an app.

Whenever I18n::MissingTranslationData exception is caught, ITS tries to add a new key into your translation file,
generates new translation for it and does it within all locales you have defined in your app.

Installation

Nothing fancy, just add gem 'i18n_translation_spawner' and run bundle install

Then add following line in an initializer, (e.g. /config/initializers/i18n.rb)

I18n.exception_handler = I18n::TranslationSpawner.new

Configuration

There is a number customizations possible to achieve with ITS

Automatic translations

If you want some keys being translated in a specific way, you can add those to default_translations

Then for instance the following key customer.new.button_submit will be automatically assigned with translation of “Create”

Automatic prefix removal

By default ITS humanizes the last part of key (“link_new_candidate” becomes “Link new candidate”).
If you want to automatically strip some of prefixes before humanization occurs, specify those in removable_prefixes

Hacking file selection

If you have more complex structure of yaml files placement, you can always add some custom logic for it.
In this example, the first part of key can be a directory name, and in case of no directory with that name, it can be a file name.
If the directory is found, the second part of key is the file name within it (imagine having files like common.en-GB.yml and customer/common.en-GB.yml)

Hacking exception catching

If you have some custom translation inheritance mechanism that is based on catching I18n::MissingTranslationData, you can always
incorporate it as well. In this case, the prefix is being stripped and translating re-attempted before re-raising an exception.