composer require google/cloud-translate
<?php
# Includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';
# Imports the Google Cloud client library
use Google\Cloud\Translate\TranslateClient;
# Your Google Cloud Platform project ID
$projectId = 'voice-184406';
# Your Google login information
putenv('GOOGLE_APPLICATION_CREDENTIALS=/var/www/html/google_api/voice.json');
# Instantiates a client
$translate = new TranslateClient([
'projectId' => $projectId
]);
####variables####
$text=$argv['1'];
$lang=$argv['2'];
# The text to translate
# The target language
$target = "$lang";
# Translates some text into spanish
$translation = $translate->translate($text, [
'target' => $target
]);
echo 'Text: ' . $text . '
Translation: ' . $translation['text'];
?>
php translator.php " Hola gracias por leer este articulo" en
Text: Hola gracias por leer este articulo
Translation: Hi, thanks for reading this article
https://cloud.google.com/translate/docs/reference/libraries
https://cloud.google.com/translate/docs/languages
No hay comentarios:
Publicar un comentario