Sha256: 96ebff488dfe4a420edd3f85221dd9fbd55709bd419a5ba5fa50bd38c90b9e9a

Contents?: true

Size: 521 Bytes

Versions: 3

Compression:

Stored size: 521 Bytes

Contents

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
      valid? ? google_translate : 'Error when translating'
    end

    def valid?
      (!@text.nil? && !@text.empty?) && !@to.nil?
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
babel_i18n-0.0.6 lib/babel_i18n/translate.rb
babel_i18n-0.0.5 lib/babel_i18n/translate.rb
babel_i18n-0.0.4 lib/babel_i18n/translate.rb