PHPackages                             potsky/microsoft-translator-php-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. potsky/microsoft-translator-php-sdk

ActiveLibrary[Localization &amp; i18n](/categories/localization)

potsky/microsoft-translator-php-sdk
===================================

PHP SDK for Microsoft Translator

v0.0.3(8y ago)18120.2k↓37.5%2[1 issues](https://github.com/potsky/microsoft-translator-php-sdk/issues)1MITPHP

Since Feb 16Pushed 8y ago2 watchersCompare

[ Source](https://github.com/potsky/microsoft-translator-php-sdk)[ Packagist](https://packagist.org/packages/potsky/microsoft-translator-php-sdk)[ Docs](https://github.com/potsky/microsoft-translator-php-sdk)[ RSS](/packages/potsky-microsoft-translator-php-sdk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (3)Used By (1)

PHP SDK for Microsoft Translator
================================

[](#php-sdk-for-microsoft-translator)

[![Latest Stable Version](https://camo.githubusercontent.com/e3e3dbf966547ff2382b2b90fa818ed29c1523c279fd96aa6914c2ba8d706b5b/68747470733a2f2f706f7365722e707567782e6f72672f706f74736b792f6d6963726f736f66742d7472616e736c61746f722d7068702d73646b2f762f737461626c652e737667)](https://packagist.org/packages/potsky/microsoft-translator-php-sdk)[![Total Downloads](https://camo.githubusercontent.com/a663f1c01cc16a3c986db0e2d5065cb4da62b6d40dce41d7b08b8c9adb363066/68747470733a2f2f706f7365722e707567782e6f72672f706f74736b792f6d6963726f736f66742d7472616e736c61746f722d7068702d73646b2f646f776e6c6f6164732e737667)](https://packagist.org/packages/potsky/microsoft-translator-php-sdk)[![Build Status](https://camo.githubusercontent.com/cfa19151c787a55ce1529220c3d4ed2274b764d2b1f27c42703c1b755c4b9cb6/68747470733a2f2f7472617669732d63692e6f72672f706f74736b792f6d6963726f736f66742d7472616e736c61746f722d7068702d73646b2e737667)](https://travis-ci.org/potsky/microsoft-translator-php-sdk)[![Coverage Status](https://camo.githubusercontent.com/4e75515c8d056b76155a7ea43bfed4b4bd805e1823d8026beeff6580cd8c24a1/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f706f74736b792f6d6963726f736f66742d7472616e736c61746f722d7068702d73646b2f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/potsky/microsoft-translator-php-sdk?branch=master)

Table of content
----------------

[](#table-of-content)

1. [Installation](#user-content-1-installation)
2. [Configuration](#user-content-2-configuration)
3. [Usage](#user-content-3-usage)
4. [Change Log](#user-content-4-change-log)
5. [Contribute](#user-content-5-contribute)

1. Installation
---------------

[](#1-installation)

### Requirements

[](#requirements)

The SDK needs the [cURL PHP extension](http://php.net/manual/fr/book.curl.php).

### With composer

[](#with-composer)

Install the latest stable version using composer: `composer require potsky/microsoft-translator-php-sdk`

Or add `potsky/microsoft-translator-php-sdk` to your `composer.json` :

```
{
    "require": {
        "potsky/microsoft-translator-php-sdk": "*"
    }
}
```

### Manually

[](#manually)

Is it time to move to composer?

Not now? Ok, just include `src/MicrosoftTranslator.php` in your PHP script :

```
include_once( 'src/MicrosoftTranslator.php' );
```

2. Configuration
----------------

[](#2-configuration)

### 2.1 Microsoft Account

[](#21-microsoft-account)

1. Sign up for a Microsoft Azure account (credit card required)

    If you don’t already have an Azure account, sign up for a Microsoft Azure account at .
2. After you have created an Azure account, subscribe to Azure. You will not be charged for Azure unless you use it. Then sign into the Azure portal at .
3. Add a Microsoft Translator API subscription to your Azure account.

    - Select the *+ New* option
    - Select *AI + Cognitive Services* from the list of Azure services
    - Select either *Translator Text API*
    - Press the *Create* button when you’re ready to create your Microsoft Translator API subscription.
    - Complete the fields and press the *Create* button and you’re now subscribed to Microsoft Translator.
4. Retrieve your authentication key.

    - Go to *All Resources* and select the *Microsoft Translator API* subscription account you are subscribed to.
    - Select the *Keys* option and copy the first subscription key to access the service.

### 2.2 SDK

[](#22-sdk)

When instantiating a new client, you pass an array of configuration parameters:

```
$msTranslator = new MicrosoftTranslator\Client( $configuration );
```

Here is the list of available parameters, some are mandatory:

NameDefaultDescription`api_client_key`**mandatory**Your subscription key 1`api_access_token`-You can directly give an access token. In this case `api_client_key` will not be used but this token longs only 10 minutes according to the microsoft documentation`api_base_url``http://api.microsofttranslator.com/V2/Http.svc/``auth_base_url``https://datamarket.accesscontrol.windows.net/v2/OAuth2-13/``guard_type``file`The only available type is `file` but you can specify your own Guard by setting the classname like this `YourNameSpace\\YourGuardWhichImplementsTheMicrosoftTranslatorGuardInterface``guard_file_dir_path`The default PHP tmp directoryYou can specify a custom directory. **IT MUST NOT BE EXPOSED TO INTERNET** given that clear access token will be stored in files...`log_level`No logTo enable log, choose the maximum severity you want to log in this list : `\MicrosoftTranslator\Logger::LEVEL_DEBUG`, `\MicrosoftTranslator\Logger::LEVEL_INFO`, `\MicrosoftTranslator\Logger::LEVEL_WARNING`, `\MicrosoftTranslator\Logger::LEVEL_ERROR` and `\MicrosoftTranslator\Logger::LEVEL_FATAL``log_file_path`No file path, output with error\_log() functionSet a file path to log in this file`http_timeout``10`The timeout in seconds for requests`http_proxy_host`-The proxy host if you need a proxy for outgoing connections to the API`http_proxy_type``URLPROXY_HTTP`One of these values: `URLPROXY_HTTP`, `CURLPROXY_SOCKS4`, `CURLPROXY_SOCKS5``http_proxy_auth``CURLAUTH_BASIC`One if these values: `CURLAUTH_BASIC`, `CURLAUTH_NTLM``http_proxy_port``3128`The proxy port`http_proxy_user`-The proxy user name if your proxy needs authentication`http_proxy_pass`-The proxy user password if your proxy needs authentication`http_user_agent``MicrosoftTranslator PHP SDK v%VERSION%`You can use your own user agent and you can use the placeholder `%VERSION%` to inject the current SDK version3. Usage
--------

[](#3-usage)

### 3.1 Methods

[](#31-methods)

Define a client with your credentials:

```
