Class: FastGettext::TranslationRepository::Merge
- Defined in:
- lib/fast_gettext/translation_repository/merge.rb
Overview
Responsibility:
- merge data from multiple repositories into one hash structure
- can be used instead of searching for translations in multiple domains
- requires reload when current locale is changed
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #[](key) ⇒ Object
- #add_repo(repo) ⇒ Object
- #available_locales ⇒ Object
- #clear ⇒ Object
-
#initialize(name, options = {}) ⇒ Merge
constructor
A new instance of Merge.
- #plural(*keys) ⇒ Object
- #pluralisation_rule ⇒ Object
- #reload ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Merge
Returns a new instance of Merge.
12 13 14 15 16 17 18 |
# File 'lib/fast_gettext/translation_repository/merge.rb', line 12 def initialize(name, = {}) clear super(name, ) .fetch(:chain, []).each do |repo| add_repo(repo) end end |
Instance Method Details
#[](key) ⇒ Object
58 59 60 |
# File 'lib/fast_gettext/translation_repository/merge.rb', line 58 def [](key) @data[key] end |
#add_repo(repo) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/fast_gettext/translation_repository/merge.rb', line 50 def add_repo(repo) raise "Unsupported repository" unless repo_supported?(repo) @repositories << repo load_repo(repo) true end |
#available_locales ⇒ Object
20 21 22 |
# File 'lib/fast_gettext/translation_repository/merge.rb', line 20 def available_locales @repositories.flat_map(&:available_locales).uniq end |
#clear ⇒ Object
62 63 64 65 |
# File 'lib/fast_gettext/translation_repository/merge.rb', line 62 def clear @repositories = [] @data = {} end |
#plural(*keys) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/fast_gettext/translation_repository/merge.rb', line 33 def plural(*keys) @repositories.each do |r| result = r.plural(*keys) return result unless result.compact.empty? end [] end |
#pluralisation_rule ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/fast_gettext/translation_repository/merge.rb', line 24 def pluralisation_rule @repositories.each do |r| if result = r.pluralisation_rule return result end end nil end |
#reload ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/fast_gettext/translation_repository/merge.rb', line 41 def reload @data = {} @repositories.each do |r| r.reload load_repo(r) end super end |