2017 © Pedro Peláez
 

library microsoft-translator

Library for making calls to the Microsoft Translator V2 API

image

maxvanceffer/microsoft-translator

Library for making calls to the Microsoft Translator V2 API

  • Thursday, August 7, 2014
  • by maxvanceffer
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 20 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

PHP library for the Microsoft Translator V2 API

By Matthias Noback, (*1)

Build Status Scrutinizer Quality Score, (*2)

Installation

Using Composer, add to composer.json:, (*3)

{
    "require": {
        "matthiasnoback/microsoft-translator": "dev-master"
    }
}

Then using the Composer binary:, (*4)

php composer.phar install

Usage

This library uses the Buzz browser to make calls to the Microsoft Translator V2 API., (*5)

You need to register your application at the Azure DataMarket and thereby retrieve a "client id" and a "client secret". These kan be used to instantiate the AccessTokenProvider on which the MicrosoftTranslator depends:, (*6)

<?php

use Buzz\Browser;
use MatthiasNoback\MicrosoftOAuth\AccessTokenProvider;
use MatthiasNoback\MicrosoftTranslator\MicrosoftTranslator;

$browser = new Browser();

$clientId = '[YOUR-CLIENT-ID]';
$clientSecret = '[YOUR-CLIENT-SECRET]';

$accessTokenProvider = new AccessTokenProvider($browser, $clientId, $clientSecret);

$translator = new MicrosoftTranslator($browser, $accessTokenProvider);

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:, (*7)

<?php

use MatthiasNoback\MicrosoftOAuth\AccessTokenCache;
use Doctrine\Common\Cache\ArrayCache;

$cache = new ArrayCache();
$accessTokenCache = new AccessTokenCache($cache);
$accessTokenProvider->setCache($accessTokenCache);

The actual cache provider can be anything, as long as it implements the Cache interface from the Doctrine Common library., (*8)

Making calls

Translate a string

$translatedString = $translator->translate('This is a test', 'nl', 'en');

// $translatedString will be 'Dit is een test', which is Dutch for...

Translate a string and get multiple translations

$matches = $translator->getTranslations('This is a test', 'nl', 'en');

foreach ($matches as $match) {
    // $match is an instance of MatthiasNoback\MicrosoftTranslator\ApiCall\TranslationMatch
    $degree = $match->getDegree();
    $translatedText = $match->getTranslatedText();
}

Detect the language of a string

$text = 'This is a test';

$detectedLanguage = $translator->detect($text);

// $detectedLanguage will be 'en'

Get a spoken version of a string

$text = 'My name is Matthias';

$spoken = $translator->speak($text, 'en', 'audio/mp3', 'MaxQuality');

// $spoken will be the raw MP3 data, which you can save for instance as a file

Tests

Take a look at the tests to find out what else you can do with the API., (*9)

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)., (*10)

Build Status, (*11)

There is a MicrosoftTranslatorBundle which makes the Microsoft translator available in a Symfony2 project., (*12)

There is also a MicrosoftTranslatorServiceProvider which registers the Microsoft translator and related services to a Silex application., (*13)

TODO

There are some more calls to be implemented, and also some more tests to be added., (*14)

The Versions

07/08 2014

dev-master

9999999-dev http://github.com/matthiasnoback/microsoft-translator

Library for making calls to the Microsoft Translator V2 API

  Sources   Download

MIT

The Requires

 

translate bing microsoft translator

29/01 2014

v0.4.2

0.4.2.0 http://github.com/matthiasnoback/microsoft-translator

Library for making calls to the Microsoft Translator V2 API

  Sources   Download

MIT

The Requires

 

The Development Requires

translate bing microsoft translator

29/01 2014

v0.4.1

0.4.1.0 http://github.com/matthiasnoback/microsoft-translator

Library for making calls to the Microsoft Translator V2 API

  Sources   Download

MIT

The Requires

 

translate bing microsoft translator

29/01 2014

v0.4.0

0.4.0.0 http://github.com/matthiasnoback/microsoft-translator

Library for making calls to the Microsoft Translator V2 API

  Sources   Download

MIT

The Requires

 

translate bing microsoft translator

29/01 2014

v0.3.1

0.3.1.0 http://github.com/matthiasnoback/microsoft-translator

Library for making calls to the Microsoft Translator V2 API

  Sources   Download

MIT

The Requires

 

translate bing microsoft translator

29/01 2014

v0.3.0

0.3.0.0 http://github.com/matthiasnoback/microsoft-translator

Library for making calls to the Microsoft Translator V2 API

  Sources   Download

MIT

The Requires

 

translate bing microsoft translator

16/07 2013

v0.2.0

0.2.0.0 http://github.com/matthiasnoback/microsoft-translator

Library for making calls to the Microsoft Translator V2 API

  Sources   Download

MIT

The Requires

 

translate bing microsoft translator

16/12 2012

v0.1.0

0.1.0.0 http://github.com/matthiasnoback/microsoft-translator

Library for making calls to the Microsoft Translator V2 API

  Sources   Download

MIT

The Requires

 

translate bing microsoft translator