Class: SimpleARLocalizer::Localizer
- Inherits:
-
Object
- Object
- SimpleARLocalizer::Localizer
- Includes:
- Singleton
- Defined in:
- lib/simple_ar_localizer/localizer.rb
Overview
Localizer provides a slightly easier way of hooking into the depths of Rails’ Internationalization functionality.
By default, it allows you to specify the human name (with plurality), human attribute names, and any custom error messages on both a per-model and per-attribute level via a simple hash… rather than having to worry about exactly where things get nested in .YAML files.
It takes a bit of explaining to start with, but should be way nicer in the long-run =)
Class Method Summary collapse
-
.transform(model_name, language, l10n_data) ⇒ Object
Does the actual translation from the nicely-formatted hash, to a more Rails i18n-friendly one.
Instance Method Summary collapse
-
#initialize ⇒ Localizer
constructor
Constructor logic.
Constructor Details
#initialize ⇒ Localizer
Constructor logic. This should not be called directly.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/simple_ar_localizer/localizer.rb', line 16 def initialize @custom_rules = {} # if we have a custom startup hook if defined?( Rails ) and Rails.application.config.respond_to?( :ar_localization_rules ) @custom_rules = Rails.application.config.ar_localization_rules end end |
Class Method Details
.transform(model_name, language, l10n_data) ⇒ Object
Does the actual translation from the nicely-formatted hash, to a more Rails i18n-friendly one.
Parameters
- model_name
-
the model we’re specifying localisations for
- language
-
the ISO-639 language code of the language we’re providing a localisation for
- L10n_data
-
a hash containing localisation data for the model/language combination
36 37 38 39 40 |
# File 'lib/simple_ar_localizer/localizer.rb', line 36 def self.transform( model_name, language, l10n_data ) self.instance.send( :perform_translation, model_name, language, l10n_data ) end |