Class: C11n::Translations
- Inherits:
-
Object
- Object
- C11n::Translations
- Defined in:
- lib/c11n/translations.rb
Instance Attribute Summary collapse
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
- #add_translation(locale, key, value) ⇒ Object
- #add_translations(locale, translations) ⇒ Object
- #export_with(exporter, locale) ⇒ Object
- #import_with(importer, given_locale = nil) ⇒ Object
-
#initialize(options = {}) ⇒ Translations
constructor
A new instance of Translations.
- #to_hash ⇒ Object
- #translation(locale, key) ⇒ Object
- #translations_for(locale) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Translations
Returns a new instance of Translations.
7 8 9 10 |
# File 'lib/c11n/translations.rb', line 7 def initialize( = {}) @translations = {} @deserializer_class = [:deserializer_class] || C11n::Conversion::ComposedKeyDeserializer end |
Instance Attribute Details
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
5 6 7 |
# File 'lib/c11n/translations.rb', line 5 def categories @categories end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
5 6 7 |
# File 'lib/c11n/translations.rb', line 5 def types @types end |
Instance Method Details
#add_translation(locale, key, value) ⇒ Object
12 13 14 |
# File 'lib/c11n/translations.rb', line 12 def add_translation(locale, key, value) translations_for(locale.to_sym)[key] = value end |
#add_translations(locale, translations) ⇒ Object
20 21 22 |
# File 'lib/c11n/translations.rb', line 20 def add_translations(locale, translations) @translations[locale.to_sym] = translations end |
#export_with(exporter, locale) ⇒ Object
37 38 39 |
# File 'lib/c11n/translations.rb', line 37 def export_with(exporter, locale) exporter.export(self, locale) end |
#import_with(importer, given_locale = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/c11n/translations.rb', line 24 def import_with(importer, given_locale = nil) importer.import.each do |locale, imported| next if given_locale && given_locale.to_sym != locale.to_sym add_translations(locale, imported) end @categories = importer.categories @types = importer.types self end |
#to_hash ⇒ Object
45 46 47 |
# File 'lib/c11n/translations.rb', line 45 def to_hash @translations end |
#translation(locale, key) ⇒ Object
16 17 18 |
# File 'lib/c11n/translations.rb', line 16 def translation(locale, key) translations_for(locale.to_sym)[key] end |
#translations_for(locale) ⇒ Object
41 42 43 |
# File 'lib/c11n/translations.rb', line 41 def translations_for(locale) @translations[locale.to_sym] ||= {} end |