PHP code example of collab / module-google-translate-service
1. Go to this page and download the library: Download collab/module-google-translate-service library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
collab / module-google-translate-service example snippets
...
use Collab\GoogleTranslateService\Service\CloudTranslate;
...
public function __construct(
protected CloudTranslate $cloudTranslate
) {
}
...
$text = 'Hello, world!';
$targetLanguage = 'fr';
// Basic translation
$output = $this->cloudTranslate->translate($text, $targetLanguage);
// $output = 'Bonjour le monde !'
// Translation with source language specified
$output = $this->cloudTranslate->translate($text, $targetLanguage, 'en');
// Detect language
$detectedLanguage = $this->cloudTranslate->detectLanguage($text);
// $detectedLanguage = 'en'
// Get supported languages
$supportedLanguages = $this->cloudTranslate->getSupportedLanguages();
...