justinfrench/formtastic — pull request #716 by nathanl (2011-10-12 13:30:31+00:00)
Title: Ability to customize localization

## Who's this guy?

I just changed my Github username - `nathanl` was formerly `sleeplessgeek`. I have a few patches in already. :)

Though the commit is under my name, I worked on this with @adamhunter.

## The changes

Pull localization behavior of `localized_string` into a separate class, and add configuration option to allow users to specify their own custom localizer class. The default configuration is: `FormBuilder.i18n_localizer = Formtastic::Localizer`

All tests are green, though I would love to have some other eyes on this to see if we missed anything (maybe there are gaps in the test coverage?), since this is a biggish change. In particular, we've only used it on forms for models.

Also updated documentation and generator to reflect this change.

## Why?

We needed this for our own use - see my Gist here: https://gist.github.com/23184d8536f22bb2a8d3

However, this is also a step towards answering the concern in this ticket: https://github.com/justinfrench/formtastic/issues/445

Namely, if you want to change the way Formtastic does localization, but maintain backwards compatibility, you could:

- Rename `Formtastic::Localizer` to something like `Formtastic::LegacyLocalizer`
- Create a new `Formtastic::Localizer` with the desired behavior
- Default to the legacy localizer so people upgrading aren't affected, but for new projects, generate a configuration that points to the new one.

For that matter, you could provide as many localization classes as you like out of the box and let people pick the one they like best.

Thoughts? Attaboys? Howls of derisive laughter?