class Translatomatic::Provider::GoogleWeb
Google
translation web interface. supports multiple translations @see translate.google.com.au
Attributes
dt[RW]
Public Class Methods
new(options = {})
click to toggle source
Create a new GoogleWeb
provider instance
Calls superclass method
Translatomatic::Provider::Base::new
# File lib/translatomatic/provider/google_web.rb, line 15 def initialize(options = {}) super(options) require 'google_web_translate' @dt = %w[t at] @debug = options[:debug] end
supports_alternative_translations?()
click to toggle source
(see Base.supports_alternative_translations?
)
# File lib/translatomatic/provider/google_web.rb, line 10 def self.supports_alternative_translations? true end
Public Instance Methods
languages()
click to toggle source
(see Base#languages
)
# File lib/translatomatic/provider/google_web.rb, line 23 def languages api.respond_to?(:languages) ? api.languages : [] end
Private Instance Methods
api()
click to toggle source
# File lib/translatomatic/provider/google_web.rb, line 29 def api options = { debug: @debug, dt: @dt, http_client: http_client } @api ||= GoogleWebTranslate::API.new(options) end
perform_translate(strings, from, to)
click to toggle source
# File lib/translatomatic/provider/google_web.rb, line 34 def perform_translate(strings, from, to) strings.each do |string| result = api.translate(string, from, to) add_translations(string, translations_from_result(result)) end end
translations_from_result(result)
click to toggle source
# File lib/translatomatic/provider/google_web.rb, line 41 def translations_from_result(result) if result.alternatives.present? result.alternatives else result.translation end end