Class: Translatomatic::Translation::Fetcher

Inherits:
Object
  • Object
show all
Includes:
Munging, Util
Defined in:
lib/translatomatic/translation/fetcher.rb

Overview

Fetches translations from the database and translation providers

Instance Method Summary collapse

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(options = {})
  ATTRIBUTES.each do |i|
    instance_variable_set("@#{i}", options[i])
  end
end

Instance Method Details

#translationsArray<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.

Returns:

  • (Array<Result>)

    List of translations



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