require 'google/api' module BabelI18n class Translate include Google::API attr_accessor :text, :key def initialize(text) @text = text @from, @to = nil, nil end def from(from) @from = from end def to(to) @to = to end def target @to end def source @from end def translate google_translate if valid? end def valid? raise "parameter 'text' is necessary to translate" if @text.nil? || @text.empty? raise "parameter 'to' is necessary to translate" if @to.nil? || @to.empty? true end end end