Skip to content

badams/microsoft-translator

Repository files navigation

Software License Build Status Coverage Status Quality Score

MicrosoftTranslator

An easy to use PHP implementation of Microsoft's Translator API

The goal of this project is to provide a modern, elegant, and feature complete implementation of the Microsoft Translation HTTP API to PHP developers.

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.

Installation

Install badams/microsoft-translator using Composer.

$ 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.

$ composer test

License

MicrosoftTranslator is open-sourced software licensed under the MIT License (MIT). Please see LICENSE for more information.

About

🌍 PHP implementation of Microsoft's Translator API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages