maxvanceffer / microsoft-translator-bundle
Bundle for using the Microsoft Translator V2 API (Fork to be able checkout with symfony 2.4)
Installs: 18
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 5
Type:symfony-bundle
Requires
- matthiasnoback/microsoft-translator: 0.*
- symfony/framework-bundle: >=2.1,<2.4-dev
This package is not auto-updated.
Last update: 2024-11-05 01:47:39 UTC
README
By Matthias Noback
Installation
Using Composer, add to composer.json
:
{
"require": {
"matthiasnoback/microsoft-translator-bundle": "dev-master"
}
}
Then using the Composer binary:
php composer.phar install
Register the bundle in /app/AppKernel.php
:
<?php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new MatthiasNoback\MicrosoftTranslatorBundle\MatthiasNobackMicrosoftTranslatorBundle(),
);
}
}
Usage
This bundle wraps the corresponding Microsoft Translator V2 API PHP library
and adds the translator as the service microsoft_translator
to your service container.
You need to register your application at the Azure DataMarket and
thereby retrieve a "client id" and a "client secret". Copy these values to the right keys in config.yml
:
matthias_noback_microsoft_translator:
oauth:
client_id: "YOUR-CLIENT-ID"
client_secret: "YOUR-CLIENT-SECRET"
Making calls
Translate a string
// in your controller
$translatedString = $this->get('microsoft_translator')->translate('This is a test', 'nl', 'en');
// $translatedString will be 'Dit is een test', which is Dutch for...
Detect the language of a string
$text = 'This is a test';
$detectedLanguage = $this->get('microsoft_translator')->detect($text);
// $detectedLanguage will be 'en'
Get a spoken version of a string
$text = 'My name is Matthias';
$spoken = $this->get('microsoft_translator')->speak($text, 'en', 'audio/mp3', 'MaxQuality');
// $spoken will be the raw MP3 data, which you can save for instance as a file
For more examples, see the README of the PHP library