PHP Classes

File: examples.md

Recommend this page to a friend!
  Classes of Mateo   PHP Google and Yandex Translate API   examples.md   Download  
File: examples.md
Role: Documentation
Content type: text/markdown
Description: Documented examples
Class: PHP Google and Yandex Translate API
Translate texts with Google or Yandex APIs
Author: By
Last change:
Date: 2 years ago
Size: 732 bytes
 

Contents

Class file image Download

Guide use

1. Use with composer

require 'path/to/vendor/autoload.php';

use Mateodioev\Translate;
$tr = new Translate;

Google

$res = $tr->google('Your text to translate', 'source_lang', 'target_lang');

Yandex

$key = 'YOUR_API_KEY'; // see: https://translate.yandex.com/developers/keys
$res = $tr->yandex($key, 'Your text to translate', 'source_lang', 'target_lang'),

Another formats

$tr->setText('Hello world!')->setInputLang('en')->setOutputLang('es');

$res = $tr->yandex($key);
$res = $tr->google();
# Use any of the above methods

Get translate text

$tr->getText();

Get lang name

$dir = 'input or output';
$tr->getLangName($dir);