1. Go to this page and download the library: Download picolab/translator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
picolab / translator example snippets
$translator = new Picolab\Translator\Translator();
// set up your translating provider from available providers
$translator->setProvider($translateProvider);
// translate:
$translation = $translator->from('en')->to('ru')->translate('Some other language');
// You can output the results immediately with echo
echo $translation;
// output:
// Другой язык
$outputResponse = $translation->getResponse();
//output:
/*
Array
(
[code] => 200
[to] => ru
[from] => en
[text] => Array
(
[0] => Другой язык
)
)
*/
// You can use language autodetect feature, if provider is supporting it:
$translation = $translator->to('ru')->translate('Some other language');
// output $translation->getResponse():
/*
Array
(
[code] => 200
[to] => ru
[from] => en
[text] => Array
(
[0] => Другой язык
)
)
*/
// You can even use arrays for translating multiple texts
$translation = $translator->to('ru')->translate(['Some other language', 'Some other value']);
// $translation->getResponse():
/*
Array
(
[code] => 200
[to] => ru
[from] => en
[text] => Array
(
[0] => Другой язык
[1] => другое значение
)
)
*/
// p.s. in this case echo $translation will output only first array item
$translator = new Picolab\Translator\Translator();
$translator->setGuzzleInstance($yourGuzzleClientInstance);
...
$translateProvider = new Picolab\Translator\Providers\YandexProvider([
'key' => 'your api key',
]);
$translateProvider = new Picolab\Translator\Providers\LetsMTProvider([
'client_id' => 'client ID',
'systemID' => 'System ID',
]);
$translator = new Picolab\Translator\Translator();
$translator->setProvider($translateProvider);
// Due to the fact that available languages is already defined in the MT system,
// you do not need to specify them there
// Translation system EN-LV
$translation = $translator->translate('Some other language');
// output first translation
echo $translation;
$translateProvider = new Picolab\Translator\Providers\GoogleProvider([
'api_key' => 'your api key'
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.