Of course, I am an amateur in this question, but I still can’t understand how the connection to yandex translate through the API key is implemented in the php code. How to implement it correctly, because the documentation does not say anything about it?

  • The issue is fully resolved! It turns out that Yandex intentionally does not translate the text 'Hello World'. Many thanks to my reply to @Etki, definitely +. - ggLike

1 answer 1

You really did not reach the third page of the documentation?

Imgur

$key = 'aaaabbbbccccdddd'; $url = sprintf('https://translate.yandex.net/api/v1.5/tr.json/getLangs?key=%s&ui=ru', $key); $data = file_get_contents($url); 
  • <? php $ key = 'trnsl.1.1.20141019T052112Z.fba5ee2ce80ee96e.e1307571361be995350710c5d9f497e47ac259d7'; $ url = sprintf (' translate.yandex.net/api/v1.5/tr.json/getLangs?key=%s&ui=ru ', $ key); $ data = file_get_contents ($ url); $ text = "Hello world"; $ lang = 'en ru'; ?> And then what? How to translate? - ggLike
  • @ggLike, use the methods described on the fifth page of the documentation $ params = array ('key' => $ key, 'lang' => 'en-ru', 'text' => 'Hello world',); $ query = http_build_query ($ params); $ response = file_get_contents (' translate.yandex.net/api/v1.5/tr.json/translate ?'. $ query); $ data = json_decode ($ response, true); $ text = $ data ['text'] [0]; - etki
  • I re-read the API but didn’t understand until the end how Yandex translate works. I tried using your method to display the text in English! - ggLike
  • @ggLike, hmm, for some reason, hello world doesn't translate. 'Can i borrow your mustache?' - with a bang. - etki
  • @Etki I wrote to you that you answered the question. Thank you very much! Above in the comments I wrote why the translation did not work. By the way, programmers in Yandex are really humorous, since they decided to close the translation of 'Hello World'. XD - ggLike