Sha256: 882534733f98730174a76900d36f64a020d092bba6a93ed418301e804afd410f
Contents?: true
Size: 1.83 KB
Versions: 8
Compression:
Stored size: 1.83 KB
Contents
$lib = File.expand_path('../lib', File.dirname(__FILE__)) require "Models/Review" require "Models/Processor" require "Helper" require "pathname" require "google/cloud/translate/v2" class GoogleTranslateProcessor < Processor attr_accessor :client, :targetLang, :territoriesExclude 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 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 end
Version data entries
8 entries across 8 versions & 1 rubygems