abeliani/string-translator

Translates the received text using various services

v1.0.0 2024-05-08 22:56 UTC

This package is auto-updated.

Last update: 2024-11-09 00:10:42 UTC


README

Translates the received text using various services

Supported services

  • MyMemory
  • Offline transliteration
  • Offline bijective transliteration

Install

composer require abeliani/string-translator

Usage

Online drivers need to pass implemented psr7 client and request instances

$driver = new MyMemoryDriver('token', $psr7Client, $psr7Request);
$translator = new TextTranslator($driver);

// set text and it languge code
$translator->setSource('some text', 'en')

// Here will be the translated text
print $translator->translate('ge');

Translate the text to many languages

print $translator->translate('fr');
// ...
print $translator->translate('tr');

Chain of driver calls. We can pass the driver into the chain, which will be called if the previous one does not complete the translation.

$driver = new OneDriver($apiKey, $psr7Client, $psr7Request, new TwoDriver($apiKey, $psr7Client, $psr7Request));
$translator = new TextTranslator($driver);

Feel free to request the creation of a new dictionary, service, or send a pull request for your dictionary or service of online translator.

Package homepage