Class: Translatomatic::Translation::Fetcher
- Inherits:
-
Object
- Object
- Translatomatic::Translation::Fetcher
- Defined in:
- lib/translatomatic/translation/fetcher.rb
Overview
Fetches translations from the database and translation providers
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Fetcher
constructor
A new instance of Fetcher.
-
#translations ⇒ Array<Result>
Fetch a list of translations for all texts given in the constructor for all providers.
Constructor Details
#initialize(options = {}) ⇒ Fetcher
Returns a new instance of Fetcher.
5 6 7 8 9 |
# File 'lib/translatomatic/translation/fetcher.rb', line 5 def initialize( = {}) ATTRIBUTES.each do |i| instance_variable_set("@#{i}", [i]) end end |
Instance Method Details
#translations ⇒ Array<Result>
Fetch a list of translations for all texts given in the constructor for all providers. Translations are fetched from the database first, then from providers.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/translatomatic/translation/fetcher.rb', line 15 def translations collection = Collection.new # add all translations from the database to the collection collection.add(find_database_translations(@texts)) if @use_db # request translations for all texts that aren't in the database untranslated = untranslated(collection) if untranslated.present? provider_translations = find_provider_translations(untranslated) save_database_translations(provider_translations) collection.add(provider_translations) end # puts collection.description collection end |