1
1

More than 3 years have passed since last update.

PHP: Google Cloud Translation API の使い方 (Basic)

Posted at
basic01.php
#! /usr/bin/php
<?php
// ------------------------------------------------------------------
//
//  basic01.php
//
//                      Nov/26/2020
//
// ------------------------------------------------------------------
require 'vendor/autoload.php';
use Google\Cloud\Translate\TranslateClient;

$text = 'Es war einmal ein kleines Mädchen.';
$targetLanguage = 'ja';

$translate = new TranslateClient();
$result = $translate->translate($text, [
    'target' => $targetLanguage,
]);
print("Source language: $result[source]\n");
print("Translation: $result[text]\n");
// ------------------------------------------------------------------
?>

実行方法

export GOOGLE_APPLICATION_CREDENTIALS=./***.json
#
./basic01.php

実行結果

Source language: de
Translation: 昔々、小さな女の子がいました。
1
1
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
1