1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Ruby: Google Cloud Translation API の使い方 (Advanced)

Posted at
advanced01.rb
#! /usr/bin/ruby
# -*- encoding: utf-8 -*-
#
#	advanced01.rb
#
#						Nov/26/2020
# ---------------------------------------------------------------------
require "google/cloud/translate"

project_id    = "project-translation"
text          = "Es war einmal ein kleines Mädchen."
target_language = "ja"
location_id = "global"

contents = [text]

client = Google::Cloud::Translate.translation_service

parent = client.location_path project: project_id, location: location_id

response = client.translate_text parent:               parent,
                                 contents:             contents,
                                 target_language_code: target_language

#
response.translations.each do |translation|
	puts "Translated text: #{translation.translated_text}"
end
#
# ---------------------------------------------------------------------

実行方法

export GOOGLE_APPLICATION_CREDENTIALS=./***.json
#
./advanced01.rb

実行結果

Translated text: 昔々、小さな女の子がいました。
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?