dir.by  
Поиск >>

Компьютер, программы
→
Yandex services for Web sites (visitor counter, street map, language translator, contextual advertising, ...)
 Yandex Translate API (language translator) 
посмотрели 11046 раз
обновлено: 18 February 2020
To use Yandex Translator you need to get a key API
Get the key API: https://translate.yandex.ru/developers/keys

Supported translator languages Yandex ...

Let's create a new file 1.php
  PHP     Let's write the code in the file 1.php
function translate_yandex_text($source_text, $lang='ru-en', & $translated_text, & $error_description)
{
     $translated_text = "";
     $error_description= "";

     // there must be a character between the words %20
     $source_text = str_replace(" ", "%20", $source_text);
    
     // your key should be here yandex api
     $yt_api_key = "trnsl.1.1.20181108T121523Z.669d96c33aec2412.c32c6acb77efd.....49f91d4904088ad722a89";

     $url = 'https://translate.yandex.net/api/v1.5/tr.json/translate?' .
          'key=' . $yt_api_key . '&' .
          'text=' . $source_text. '&' .
          'lang=' . $lang . '&' .
          'format=plain&' .
          'options=1&p=2';

     $curlObject = curl_init();

     curl_setopt($curlObject, CURLOPT_URL, $url);

     curl_setopt($curlObject, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($curlObject, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt($curlObject, CURLOPT_RETURNTRANSFER, true);

     $responseData = curl_exec($curlObject);

     curl_close($curlObject);

     $result_arr = json_decode($responseData, true); // convert to an array
     $translated_text = $result_arr['text'][0];
     $error_description= $result_arr['message'];

     if ($error_description=="")
          return true; // no errors
     return false;
}

// translate the text from English into French en-fr
$source_text = "Hello my friend";
if (translate_yandex_text($source_text, 'en-fr', & $translated_text, & $error))
     echo $translated_text; // on the screen we will see Bonjour, mon ami
else
     echo $error;
On the screen we will see
Bonjour, mon ami
 
← Previous topic
How to add a Yandex map to a website
 
Next topic →
Yandex Direct (what is contextual advertising?)
 
Your feedback ... 1 Comments
guest
29 September 2020 8:04
яндекс закрыл эту версию переводчика. Теперь там 2.0 и всё по другому.
guest (5 June 2023 14:11) Спасибо а я тыкаюсь answer
   
Your Name
Your comment (www links can only be added by a logged-in user)

Новость "Черная пятница" Dreame в Беларуси – две недели скидок до 3400 рублей
 
Yandex Metrica (information about site visits)
• Information about site visits (how many visits, from which devices) Yandex Metrica
• How to add a visit counter (Yandex Metrica) to your website
Yandex Map (cities, streets)
• How to add a Yandex map to a website
Yandex Translate
• Yandex Translate API (language translator)
Yandex Direct (contextual advertising)
• Yandex Direct (what is contextual advertising?)
Yandex Direct API (program code for managing advertising campaigns)
• Access to Yandex Direct API (test environment)
• Sandbox (test companies) Yandex Direct API
• Example "List of companies" php and Yandex Direct API (test environment)
• Access to Yandex Direct API
• Establishment of the Company (on the direct.yandex.ru website)
• Financial Token
Yandex Advertising Network (YAN)
• Yandex Advertising Network (description) | How to join | Customize
• Adding Yandex ads to your site (vertical poster with 2 ads)
• Adding Yandex ads to your site (6 ads in a line, horizontal)
• Add a second site to the Yandex Advertising Network
Yandex Webmaster (site indexing, site links internal and external, etc.)
• What is Yandex Webmaster?
• How to add Yandex Webmaster to your website
Yandex Mail
• Yandex Mail (description)
Alice Talking Speaker Yandex
• I bought a Yandex speaker mini "Alice" and I want to connect it (I use an Android phone or iPhone)
• Column mini "Alice" view payment on the yandex website (you can change the plan, payment method)
Additionally
• How do I see the SQI (Site Quality Index) value for any site?

  Ваши вопросы присылайте по почте: info@dir.by