enupal/yandex-translate

Online service for machine translation for over 40 languages.

1.0.0 2020-06-29 08:17 UTC

This package is auto-updated.

Last update: 2024-11-29 05:51:32 UTC


README

Yandex API offers text translation features for over 30 languages.

API reference in English

Requirements

  • PHP 5.3 or higher
  • cURL

Install

Via Composer

$ composer require enupal/yandex-translate

Usage

use Enupal\YaTranslate\Translate;

try {
    $tr = new Translate('yourApiKey');
    $result = $tr->translate("Hey baby, what are you doing tonight?", 'fr');
    
    echo $result;                           // Hey bébé, tu fais quoi ce soir?
    echo $result->sourceText();             // Hey baby, what are you doing tonight?
    echo $result->translationDirection();   // en-fr
    
    var_dump($result->translation());       // array (size=1)
                                            // 0 => string 'Hey bébé, tu fais quoi ce soir?'
} catch (\Enupal\YaTranslate\TranslateException $e) {
    //Handle exception
}