I18n-message is a project mainly written in Ruby, based on the MIT license.
Object-oriented abstraction for looking up translations from I18n.translate
h1. I18n Message
h2. Problems solved
h2. Classes
The Error class is the meant to work as a default Error class in ActiveModel.
I18n::Message is the main base class and is supposed to work situations such as error messages, form labels etc.
The Format class is used internally to format other strings (see below).
h2. Features
The Message class comes with six modules that each provide a single feature. This way everything's completely optional and pluggable (thus extensible and easy to customize) even though we might choose to not impose this complexity on the enduser (and maybe pick a default configuration/provide a configuration dsl instead).
h3. I18n::Message::Base
This module just takes a Message OR translation key (Symbol) and interpolation values. Calling #to_s will use the string or translate the key and interpolate the values. The module is organized in a way so that other modules can hook in easily.
h3. I18n::Message::Gettext
This module will also translate Messages. This behavior is frequently asked for by people who want to use Gettext-style translation keys in class-level calls as in validates_presence_of :foo, :message => 'The message'
h3. I18n::Message::Variants
This module adds the ability to specify Hashes as strings both at class-level and in translation data. E.g.:
validates_presence_of :foo, :message => { :short => 'Short!', :full => 'The full message!' }
Calling #to_s on the I18n::Message instance will take a variant key and try to find and use the variant. It defaults to the :short variant.
h3. I18n::Message::Formatted
This module adds the ability to specify format strings both at class-level and in translation data. E.g.:
validates_presence_of :foo, :format => 'The formatted {{message}}.'
This module also works in combination with the Variants module in the way one would expect:
validates_presence_of :foo, :message => { :short => 'foo', :full => 'FOO' } :format => { :full => 'The formatted {{message}}.' }
message.to_s(:full) would then wrap the :full variant 'FOO' into the :full format string and yield 'The formatted FOO'. message.to_s (defaults to :short) would just yield 'foo' as expected.