//
Cloud Translation API //cloud.google.com/translate/docs/reference/rest
!!! не проверял
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?php // Получить ключ API $key = 'YOUR_API_KEY'; // Подключиться к API Google Translate $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://translation.googleapis.com/v3/translations'); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Authorization: Bearer ' . $key, ]); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([ 'q' => 'Hello, world!', 'target' => 'ru', ])); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); // Получить переведенный текст $translation = json_decode($response)->translations[0]->translatedText; echo $translation; |