Class: G11n::Translator
- Inherits:
-
Object
- Object
- G11n::Translator
- Includes:
- Singleton
- Defined in:
- lib/g11n/translator.rb
Overview
Manages the configuration of the G11n library
Instance Method Summary collapse
-
#dictionary_for(the_locale) ⇒ Object
Looks and returns the right dictionary for the given locale.
-
#initialize ⇒ Translator
constructor
A new instance of Translator.
-
#locale ⇒ Symbol
The current locale.
-
#locale=(the_locale) ⇒ Object
Sets the locale.
-
#translate ⇒ Object
Forwards the method call to the right “dictionary” (a SymbolTable object) mjijackson.com/2010/04/config-revisited What it truely does the #translate method is to retrieve the right SymbolTable object from the dictionary.
-
#translations_path ⇒ String
The current path to translations.
-
#translations_path=(the_path) ⇒ Object
Sets the path where translations will be looked for.
Constructor Details
#initialize ⇒ Translator
Returns a new instance of Translator.
6 7 8 |
# File 'lib/g11n/translator.rb', line 6 def initialize reset end |
Instance Method Details
#dictionary_for(the_locale) ⇒ Object
Looks and returns the right dictionary for the given locale
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/g11n/translator.rb', line 42 def dictionary_for the_locale return @dictionaries[the_locale] if @dictionaries.has_key? the_locale # In case is already loaded if File.exists? "#{@translations_path}#{the_locale}.yaml" @dictionaries[the_locale] = SymbolMatrix.new "#{@translations_path}#{the_locale}.yaml" elsif File.exists? "#{@translations_path}#{the_locale}.yml" @dictionaries[the_locale] = SymbolMatrix.new "#{@translations_path}#{the_locale}.yml" else raise NoTranslationAvailable, "There is no translation file available for the '#{the_locale}' locale, check the tranlations source directory configuration" end end |
#locale ⇒ Symbol
Returns the current locale.
19 20 21 |
# File 'lib/g11n/translator.rb', line 19 def locale @locale end |
#locale=(the_locale) ⇒ Object
Sets the locale. Fails if the locale matches no available file
11 12 13 14 15 16 |
# File 'lib/g11n/translator.rb', line 11 def locale= the_locale unless locale_file_exists_for? the_locale raise NoTranslationAvailable, "There is no translation file available for the '#{the_locale}' locale, check the tranlations source directory configuration" end @locale = the_locale end |
#translate ⇒ Object
Forwards the method call to the right “dictionary” (a SymbolTable object) mjijackson.com/2010/04/config-revisited What it truely does the #translate method is to retrieve the right SymbolTable object from the dictionary
37 38 39 |
# File 'lib/g11n/translator.rb', line 37 def translate dictionary_for @locale end |
#translations_path ⇒ String
Returns the current path to translations.
29 30 31 |
# File 'lib/g11n/translator.rb', line 29 def translations_path @translations_path end |
#translations_path=(the_path) ⇒ Object
Sets the path where translations will be looked for
24 25 26 |
# File 'lib/g11n/translator.rb', line 24 def translations_path= the_path @translations_path = the_path end |