How to use MS Translator in Alaska?
- Eugene Lutsenko
- Posts: 1649
- Joined: Sat Feb 04, 2012 2:23 am
- Location: Russia, Southern federal district, city of Krasnodar
- Contact:
How to use MS Translator in Alaska?
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.
- Eugene Lutsenko
- Posts: 1649
- Joined: Sat Feb 04, 2012 2:23 am
- Location: Russia, Southern federal district, city of Krasnodar
- Contact:
Re: How to use MS Translator in Alaska?
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
- Eugene Lutsenko
- Posts: 1649
- Joined: Sat Feb 04, 2012 2:23 am
- Location: Russia, Southern federal district, city of Krasnodar
- Contact:
Re: How to use MS Translator in Alaska?
To write the file text_ru.txt (utf-8) for hosting, run php, download the translation in the text_en file.txt:
http://aidos.byethost5.com/translate.php
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); // закрываем
?>