Skip to content

TimGa/php-translo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Translo PHP

PHP Client for Translo API

Installing

composer require timga/php-translo

Translate

use Translo\Translo;

require 'vendor/autoload.php';

$apiKey = 'YOUR-RAPIDAPI-KEY';
$translo = new Translo($apiKey);

$textToTranslate = "Что хочешь помнить, то всегда помнишь.";
$fromLang = "ru";
$toLang = "en";

$result = $translo->translate($textToTranslate, $fromLang, $toLang);
var_dump($result);

Output:

array(3) {
  'ok' =>
  bool(true)
  'text_lang' =>
  string(2) "ru"
  'translated_text' =>
  string(47) "What you want to remember, you always remember."
}

Batch translate

use Translo\Translo;

require 'vendor/autoload.php';

$apiKey = 'YOUR-RAPIDAPI-KEY';
$translo = new Translo($apiKey);

$result = $translo->batchTranslate([
    [
        "from" => "en",
        "to" => "ru",
        "text" => "банан"
    ],
    [
        "from" => "en",
        "to" => "es",
        "text" => "Ma-ia hii\nMa-ia huu"
    ],
    [
        "from" => "auto",
        "to" => "bn",
        "text" => "bonjour"
    ]
]);
var_dump($result);

Output:

array(2) {
  'ok' =>
  bool(true)
  'batch_translations' =>
  array(3) {
    [0] =>
    array(3) {
      'from' =>
      string(2) "en"
      'to' =>
      string(2) "ru"
      'text' =>
      string(10) "банан"
    }
    [1] =>
    array(3) {
      'from' =>
      string(2) "en"
      'to' =>
      string(2) "es"
      'text' =>
      string(20) "Ma-ia hola
Ma-ia huu"
    }
    [2] =>
    array(3) {
      'from' =>
      string(2) "fr"
      'to' =>
      string(2) "bn"
      'text' =>
      string(18) "হ্যালো"
    }
  }
}

Detect

use Translo\Translo;

require 'vendor/autoload.php';

$apiKey = 'YOUR-RAPIDAPI-KEY';
$translo = new Translo($apiKey);

$result = $translo->detect("Translo is the best translator in Telegram");
var_dump($result);

Output:

array(2) {
  'ok' =>
  bool(true)
  'lang' =>
  string(2) "en"
}

About

PHP library for Translo API

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages