PHP Classes
elePHPant
Icontem

PHP Microsoft Bing Translate: Translate text with Microsoft Bing Translate API

Recommend this page to a friend!
  Info   View files Documentation   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2015-02-28 (4 years ago) RSS 2.0 feedNot enough user ratingsTotal: 255 All time: 7,652 This week: 301Up
Version License PHP version Categories
ms-bing-translate 1.0.3MIT/X Consortium ...5.0Localization, PHP 5, Web services
Description Author

This class can translate text with Microsoft Bing Translate API.

First it obtains an access token to using OAuth client credentials flow to access Microsoft Bing API on behalf of a previously registered application.

Then it can call the Bing Translate API to translate one or more texts to between two given languages.

  Performance   Level  
Name: Gideon Kombian <contact>
Classes: 2 packages by
Country: Ghana Ghana
Age: 28
All time rank: 34413 in Ghana Ghana
Week rank: 695 Up1 in Ghana Ghana Up

Details

ms-translator

Build Status Scrutinizer Code Quality

Translate text using the Bing Translate API

Instruction

Translate your texts using Microsoft's Bing Translation services HTTP API http://msdn.microsoft.com/en-us/library/ff512419.aspx

The code is based on the one provided by Microsoft at the documentation, prepared for composer. In two lines, you can have a translation service working!

Before working with the code, get your Access Token, using your MSN account. More info: http://msdn.microsoft.com/en-us/library/hh454950.aspx

Don't get confused with the clientID. It's not the Customer ID nor your account key. The clientID is the text (possibly your app name or some plain-language text) that you specified when registering your application. You can view your client id https://datamarket.azure.com/developer/applications

There is a free data tier of 2 million characters per month. Check https://datamarket.azure.com/account/datasets if you haven't used yet your monthly limit:

Installation

With Composer

The easiest way to install is via composer. Create the following composer.json file and run the php composer.phar install command to install it.

{
	...
    "require": {
        "gidkom/ms-translator": "dev-master"
    }
}

then the code


include "vendor/autoload.php";

$client_id = 'abc';
$client_secret = 'xyz';

$mt = new Gidkom\MsTranslator\MsTranslator($client_id, $client_secret);

//Translate to single language
$from  = 'en';
$to = 'fr';
return $mt->translate('Hello world', $to, $from);

// To auto detect language leave out the $from argument
return $mt->translate('Hello world', $to);


Translate to multiple languagues 
$from = 'en';
$to= ['fr', 'de'];
return $mt->multiTranslate('Hello world', $to, $from);

for a list of all supported languages and codes go to public/ms-translator-language-codes.txt

  Files folder image Files  
File Role Description
Files folder imagepublic (1 file)
Files folder imagesrc (1 directory)
Accessible without login Plain text file .gitignore Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Data Auxiliary data
Accessible without login Plain text file README.md Doc. Auxiliary data

  Files folder image Files  /  public  
File Role Description
  Accessible without login Plain text file ms-translator-language-codes.txt Data Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageGidkom (1 directory)

  Files folder image Files  /  src  /  Gidkom  
File Role Description
Files folder imageMsTranslator (1 file)

  Files folder image Files  /  src  /  Gidkom  /  MsTranslator  
File Role Description
  Plain text file MsTranslator.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:255
This week:0
All time:7,652
This week:301Up