Sha256: c8c1889cd2f94290588a385547b2026fc5a212fa8d4ab761611d1b16d6bf1e21

Contents?: true

Size: 1.29 KB

Versions: 163

Compression:

Stored size: 1.29 KB

Contents

# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'google/apis/translate_v2'
require 'base_cli'


module Samples
  # Examples for the Google Translate API
  #
  # Sample usage:
  #
  #      $ ./google-api-samples translate 'Hola!' --target='en'
  #      Hello
  #
  class Translate < BaseCli
    Translate = Google::Apis::TranslateV2

    desc 'translate PHRASE', 'Translate a phrase'
    method_option :source, type: :string
    method_option :target, type: :string, required: true
    def translate(phrase)
      translate = Translate::TranslateService.new
      translate.key = api_key

      result = translate.list_translations(phrase, options[:target], source: options[:source])
      puts result.translations.first.translated_text
    end

    default_task :translate

  end
end

Version data entries

163 entries across 163 versions & 2 rubygems

Version Path
google-api-client-0.52.0 samples/cli/lib/samples/translate.rb
google-api-client-0.51.0 samples/cli/lib/samples/translate.rb
google-api-client-0.50.0 samples/cli/lib/samples/translate.rb
google-api-client-0.49.0 samples/cli/lib/samples/translate.rb
google-api-client-0.48.0 samples/cli/lib/samples/translate.rb
google-api-client-0.47.0 samples/cli/lib/samples/translate.rb
google-api-client-0.46.2 samples/cli/lib/samples/translate.rb
google-api-client-0.46.1 samples/cli/lib/samples/translate.rb
google-api-client-0.46.0 samples/cli/lib/samples/translate.rb
google-api-client-0.45.1 samples/cli/lib/samples/translate.rb
google-api-client-0.45.0 samples/cli/lib/samples/translate.rb
google-api-client-0.44.2 samples/cli/lib/samples/translate.rb
google-api-client-0.44.1 samples/cli/lib/samples/translate.rb
google-api-client-0.44.0 samples/cli/lib/samples/translate.rb
google-api-client-0.43.0 samples/cli/lib/samples/translate.rb
google-api-client-0.42.2 samples/cli/lib/samples/translate.rb
google-api-client-0.42.1 samples/cli/lib/samples/translate.rb
google-api-client-0.42.0 samples/cli/lib/samples/translate.rb
google-api-client-0.41.2 samples/cli/lib/samples/translate.rb
google-api-client-0.41.1 samples/cli/lib/samples/translate.rb