sadonsergey/yc-ml-translate

Yandex ML Translate for Yandex Cloud (AI API)

1.0.3 2020-07-13 08:02 UTC

This package is auto-updated.

Last update: 2024-09-14 21:44:34 UTC


README

Installation

composer require "sadonsergey/yc-ml-translate"

Usage

  • You must use one of two tokens, if an OAuth token is used then we will exchange it for an IAM token. However, we will have to do this every time we request a transfer, we recommend using the IAM token.
  • You can get an IAM token yourself here
  • $OAuthToken is optional if there is a $ IAMToken.
  • $folderId is required. The ID of the directory to which you have access. Required for authorization with a user account (see UserAccount resource). Do not use this field if you are making a request on behalf of a service account.

The lifetime of an IAM token is no more than 12 hours, but it is recommended to request it more often, for example, every hour.

$yandexTranslate = new ssadon\YandexTranslate($OAuthToken, $IAMToken, $folderId);

//Translating text
$text = $yandexTranslate->translate('en', 'ru', 'cat'); 
echo $text['text']; //кошка

//You can use multiple translation
$text = $yandexTranslate->translate('en', 'ru', ['cat', 'dog']); 
echo $text[0]['text']; //кошка
echo $text[1]['text']; //собака


//Detecting language
$detect = $yandexTranslate->detectLanguage('English text');
echo $detect; //en

You can also see how this works on the basis of tests. Do not forget to start them before you start working.

License

MIT