Page 1 of 1
					
				How to use MS Translator in Alaska?
				Posted: Thu Jan 16, 2020 5:42 am
				by Eugene Lutsenko
				I would like to support a multilingual interface in the Eidos system. I used to do this through Google translator and Cygwin. But Google has become paid. This raises the question of how to use a free translator from Microsoft (possibly the Microsoft Bing Translator API) in your application written in Alaska.
			 
			
					
				Re: How to use MS Translator in Alaska?
				Posted: Fri Jan 31, 2020 9:35 am
				by Eugene Lutsenko
				I figured out how to make a translation. It's pretty simple. I make an example of translation using PHP on my ftp server "Yandex Translate API". I programmatically upload a file for translation via ftp, launch the translator, and download the result via ftp. And that's it
			 
			
					
				Re: How to use MS Translator in Alaska?
				Posted: Fri Jan 31, 2020 10:03 pm
				by Eugene Lutsenko
				To write the file text_ru.txt (utf-8) for hosting, run php, download the translation in the text_en file.txt:
Code: Select all
<?php
// Документация к API Яндекс-переводчика txt-файлов: https://yandex.ru/dev/translate/
$key = 'my key';  // Получить ключ: https://yandex.ru/dev/translate/doc/dg/concepts/api-keys-docpage/
$text = file_get_contents('text_ru.txt');                                            // Текст должен быть в кодировке UTF-8 или если он в другой - то надо здесь его перекодировать
$params = array( 'key' => $key , 'text' => $text, 'lang' => 'ru-en',);               // Задать направление перевода: 'ru-en'
$query = http_build_query($params);
$response = file_get_contents('https://translate.yandex.net/api/v1.5/tr.json/translate?'.$query);
$data = json_decode($response, true);
$text = $data['text'][0];
// echo $text;
$fp = fopen("text_en.txt", "w");     // открываем файл, если файл не существует, делается попытка создать его
fwrite($fp, $text);                  // записываем в файл текст
fclose($fp);                         // закрываем
?>