Simple translator class with some translate providers, (*1)
Usage
$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
Providers use Guzzle Http client, if you have specific guzzle client configuration, you can set up with setGuzzleInstance function, (*2)
$translator = new Picolab\Translator\Translator();
$translator->setGuzzleInstance($yourGuzzleClientInstance);
...
```
### Available providers
* [Microsoft Translator service provider](#microsoft)
* [Yandex provider](#yandex)
* [Tilde Machine Translation provider](#tilde)
* [Google Translate API provider](#google)
#### <a name="microsoft"></a> Microsoft Translator service provider
dev docs: [https://msdn.microsoft.com/en-us/library/dd576287.aspx](https://msdn.microsoft.com/en-us/library/dd576287.aspx)
```php
$translateProvider = new Picolab\Translator\Providers\BingProvider([
'client_id' => 'client id',
'client_secret' => 'client secret',
]);
Yandex provider
dev docs: https://translate.yandex.com/developers, (*3)
$translateProvider = new Picolab\Translator\Providers\YandexProvider([
'key' => 'your api key',
]);
Tilde Machine Translation provider
dev docs: http://www.tilde.com/mt/tools/api, (*4)
Due to the fact that available languages is already defined in the MT system, you do not need to specify them there, but provider class will output system
source and target language, (*5)
$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;
Google Translate API provider
dev docs: https://cloud.google.com/translate/docs/, (*6)
$translateProvider = new Picolab\Translator\Providers\GoogleProvider([
'api_key' => 'your api key'
]);
License: MIT, (*7)