I using https://github.com/google/google-api-php-client for translate.
When I try
print_r($translation->listTranslations( "John go home", "es" ));
I got
Google_Service_Translate_TranslationsListResponse Object
(
[collection_key:protected] => translations
[internal_gapi_mappings:protected] => Array
(
)
[translationsType:protected] => Google_Service_Translate_TranslationsResource
[translationsDataType:protected] => array
[modelData:protected] => Array
(
[data] => Array
(
[translations] => Array
(
[0] => Array
(
[translatedText] => John ir a casa
[detectedSourceLanguage] => en
)
)
)
)
[processed:protected] => Array
(
)
)
But when I try to get translations using getTranslations() function - i got empty array. Please advice!
It looks like the library is broken.
You can use this to get the translations out though!
$client = new Google_Client();
$client->setDeveloperKey('xxxx-your-dev-key-xxxx');
$translate = new Google_Service_Translate($client);
$translations = $translate->translations->listTranslations('Hello world!', 'fr');
var_dump($translations->data);
var_dump($translations->data['translations'][0]["translatedText"]);
Will give you
array(1) {
["translations"]=>
array(1) {
[0]=>
array(2) {
["translatedText"]=>
string(17) "Bonjour le monde!"
["detectedSourceLanguage"]=>
string(2) "en"
}
}
}
string(17) "Bonjour le monde!"
I submitted a PR that fixes this, but it hasn't been accepted yet.