Class: GoogleTranslateProcessor
- Defined in:
- lib/Processors/GoogleTranslateProcessor.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#targetLang ⇒ Object
Returns the value of attribute targetLang.
-
#territoriesExclude ⇒ Object
Returns the value of attribute territoriesExclude.
Attributes inherited from Processor
#baseExecutePath, #config, #configFilePath
Instance Method Summary collapse
-
#initialize(config, configFilePath, baseExecutePath) ⇒ GoogleTranslateProcessor
constructor
A new instance of GoogleTranslateProcessor.
- #processReviews(reviews, platform) ⇒ Object
Constructor Details
#initialize(config, configFilePath, baseExecutePath) ⇒ GoogleTranslateProcessor
Returns a new instance of GoogleTranslateProcessor.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/Processors/GoogleTranslateProcessor.rb', line 14 def initialize(config, configFilePath, baseExecutePath) @config = config @configFilePath = configFilePath @baseExecutePath = baseExecutePath keyFilePath = Helper.unwrapRequiredParameter(config, "googleTranslateAPIKeyFilePath") if Pathname.new(keyFilePath).absolute? configDir = File.dirname(configFilePath) keyFilePath = "#{configDir}#{keyFilePath}" end ENV["TRANSLATE_CREDENTIALS"] = keyFilePath @client = Google::Cloud::Translate::V2.new @targetLang = Helper.unwrapRequiredParameter(config, "googleTranslateTargetLang") @territoriesExclude = [] if !config['googleTranslateTerritoriesExclude'].nil? && config['googleTranslateTerritoriesExclude'].length > 0 @territoriesExclude = config['googleTranslateTerritoriesExclude'] end end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
12 13 14 |
# File 'lib/Processors/GoogleTranslateProcessor.rb', line 12 def client @client end |
#targetLang ⇒ Object
Returns the value of attribute targetLang.
12 13 14 |
# File 'lib/Processors/GoogleTranslateProcessor.rb', line 12 def targetLang @targetLang end |
#territoriesExclude ⇒ Object
Returns the value of attribute territoriesExclude.
12 13 14 |
# File 'lib/Processors/GoogleTranslateProcessor.rb', line 12 def territoriesExclude @territoriesExclude end |
Instance Method Details
#processReviews(reviews, platform) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/Processors/GoogleTranslateProcessor.rb', line 35 def processReviews(reviews, platform) if reviews.length < 1 return reviews end reviews.each_index do |index| if territoriesExclude.include? reviews[index].territory next end if !reviews[index].title.nil? reviews[index].title = "#{client.translate reviews[index].title, to: targetLang} (#{reviews[index].title})" end body = "#{client.translate reviews[index].body, to: targetLang}" body += "\r\n===== Translate by Google =====\r\n" body += reviews[index].body reviews[index].body = body end return reviews end |