Download the PHP package matthiasnoback/microsoft-translator without Composer
On this page you can find all versions of the php package matthiasnoback/microsoft-translator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download matthiasnoback/microsoft-translator
More information about matthiasnoback/microsoft-translator
Files in matthiasnoback/microsoft-translator
Package microsoft-translator
Short Description Library for making calls to the Microsoft Translator V2 API
License MIT
Homepage http://github.com/matthiasnoback/microsoft-translator
Informations about the package microsoft-translator
PHP library for the Microsoft Translator V3 API
By Matthias Noback (maintained by Alayn Gortazar)
Installation
Using Composer, add to composer.json
:
{
"require": {
"matthiasnoback/microsoft-translator": "dev-master"
}
}
Then using the Composer binary:
php composer.phar install
Usage
This library uses the Buzz browser to make calls to the Microsoft Translator Text API 3.0.
You need to obtain a Microsoft Azure Cognitive Services subscription Key. This can be used to instantiate the AzureTokenProvider
:
Selecting azure token provider url
By default the acesstoken will be retrieved from https://api.cognitive.microsoft.com/sts/v1.0/issueToken , a third parameter can be passed to the AzureTokenProvider to choose another source.
Optional: enable the access token cache
Each call to the translator service is preceded by a call to Microsoft's OAuth server. Each access token however, may be
cached for 10 minutes, so you should also use the built-in AccessTokenCache
:
The actual cache provider can be anything, as long as it implements the CachePoolInterface
interface from FIG-PSR6
Making calls
Translate a string
Translate a string and get multiple translations
Detect the language of a string
Tests
Take a look at the tests to find out what else you can do with the API.
To fully enable the test suite, you need to copy phpunit.xml.dist
to phpunit.xml
and replace the placeholder
values with their real values (i.e. client id, client secret and a location for storing spoken text files).
TODO
- There are some more calls to be implemented, and also some more tests to be added.