27 lines
857 B
PHP
Executable File
27 lines
857 B
PHP
Executable File
<?php
|
|
require '/datas/07Prod/include/vendor/autoload.php'; // Assurez-vous que Composer a généré l'autoload
|
|
use Google\Cloud\Translate\V2\TranslateClient;
|
|
// use Google\Cloud\Translate\V3\TranslationServiceClient;
|
|
|
|
function gTranslate($txt, $targetLanguage) {
|
|
$mesg='';
|
|
|
|
// $projectId = 'TON_PROJECT_ID'; // obligatoire en V3
|
|
|
|
// Initialisez le client de traduction avec votre clé API
|
|
$translate = new TranslateClient([
|
|
'key' => 'AIzaSyCOVWNMD4_XLIDLyTL3KFSFR-Xrz2uJudU' // Remplacez par votre clé API Google
|
|
]);
|
|
|
|
// Traduction
|
|
$translation = $translate->translate( $txt, ['target' => $targetLanguage] );
|
|
|
|
// Affiche la traduction
|
|
if (isset($debug[1]) && $debug[1] == '1' ) {
|
|
echo 'Texte original : ' .$txt. "\n";
|
|
echo 'Traduction en allemand : ' .$translation['text']. "\n";
|
|
}
|
|
return $translation['text'];
|
|
}
|
|
?>
|