, (*1)
MicrosoftTranslator
The goal of this project is to provide a modern, elegant, and feature complete implementation of the Microsoft Translation HTTP API to PHP developers., (*2)
Currently supported methods
-
Translate: Converts a string of text from one language to another.
-
Detect: Detects the language of a selection of text.
-
Speak: Generates a wave form of synthesised speech from the given text/language combination.
- GetLanguagesForSpeak: Obtains a list of the language codes supported by the Translator Service for speech synthesis.
- GetLanguageNames: Retrieves localized names for the languages passed to it.
- GetLanguagesForTranslate: Obtains a list of the language codes supported by the Translator Service.
- GetTranslations: Returns an array of alternative translations of the given text.
- GetTranslationsArray: Returns an array of alternative translations of the passed array of text.
Roadmap
API methods that are yet to be implemented., (*3)
Installation
Install badams/microsoft-translator
using Composer., (*4)
$ composer require badams/microsoft-translator
Basic Usage
use badams\MicrosoftTranslator\MicrosoftTranslator;
$clientId = 'YOUR_CLIENT_ID';
$clientSecret = 'YOUR_CLIENT_SECRET';
$translator = new MicrosoftTranslator();
$translator->setClient($clientId, $clientSecret);
// Translate a string of text from one language to another
$output = $translator->translate('Hello World!', $to = 'fr', $from = 'en');
echo $output; // Salut tout le monde!
// Detect the language of a string
$language = $translator->detect('Salut tout le monde!');
echo $language; // fr
echo $language->getEnglishName(); // French
//Returns a wave or mp3 stream of the passed-in text being spoken in the desired language.
$data = $translator->speak('Salut tout le monde!', 'fr');
header('Content-Type: audio/mp3');
echo base64_decode($data);
Testing
MicrosoftTranslator
has a PHPUnit test suite. To run the tests, run the following command from the project folder., (*5)
bash
$ composer test
, (*6)
License
MicrosoftTranslator is open-sourced software licensed under the MIT License (MIT). Please see LICENSE for more information., (*7)