PHPackages                             gino-pane/phpolyglot - 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. gino-pane/phpolyglot

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

gino-pane/phpolyglot
====================

PHP package for translation, spelling correction and text-to-speech (TTS) synthesis using external APIs

v1.1.1(8y ago)9361[1 issues](https://github.com/GinoPane/PHPolyglot/issues)1MITPHPPHP ^7.1

Since Dec 2Pushed 8y ago1 watchersCompare

[ Source](https://github.com/GinoPane/PHPolyglot)[ Packagist](https://packagist.org/packages/gino-pane/phpolyglot)[ Docs](http://github.com/GinoPane/PHPolyglot)[ RSS](/packages/gino-pane-phpolyglot/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (7)Versions (6)Used By (1)

PHPolyglot
==========

[](#phpolyglot)

[![Latest Stable Version](https://camo.githubusercontent.com/cbec9a589721573c00c5e1b9668a8d40f575409ed524c01fe92d437ad2c276ab/68747470733a2f2f706f7365722e707567782e6f72672f67696e6f2d70616e652f7068706f6c79676c6f742f762f737461626c65)](https://packagist.org/packages/gino-pane/phpolyglot)[![Build Status](https://camo.githubusercontent.com/9c2c45dc9db1ce4797dfcb9ccf619b80f082331a5731137907c58e3a80032f10/68747470733a2f2f7472617669732d63692e6f72672f47696e6f50616e652f5048506f6c79676c6f742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/GinoPane/PHPolyglot)[![Maintainability](https://camo.githubusercontent.com/ac357b52885d47ef3850b7a7875902794f68bf4fd13767f65b60b3b5afab1a3a/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f62316532623630343236313266363766376531332f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/GinoPane/PHPolyglot/maintainability)[![Test Coverage](https://camo.githubusercontent.com/b14cb238c71b27994c20f34d64f70b749083d557201500af5a53fd2ea1df0f8a/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f62316532623630343236313266363766376531332f746573745f636f766572616765)](https://codeclimate.com/github/GinoPane/PHPolyglot/test_coverage)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/a7905c2e1aacccb30f569723ba3a398e71acc62471598fe5ec2b4b34c9240000/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f47696e6f50616e652f7068706f6c79676c6f742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/GinoPane/phpolyglot/?branch=master)[![License](https://camo.githubusercontent.com/de73a10fa815f4138bbd6987d66fdba3d8ee3f12a79f7efd83bcb549c396fcc6/68747470733a2f2f706f7365722e707567782e6f72672f67696e6f2d70616e652f7068706f6c79676c6f742f6c6963656e7365)](https://packagist.org/packages/gino-pane/phpolyglot)[![Total Downloads](https://camo.githubusercontent.com/5d93b8858d840b7668fcf4374676a49c3df4d8b8cd54a32c6053b6baf844b020/68747470733a2f2f706f7365722e707567782e6f72672f67696e6f2d70616e652f7068706f6c79676c6f742f646f776e6c6f616473)](https://packagist.org/packages/gino-pane/phpolyglot)

Combining and featuring different APIs for language translation, dictionary lookup, spelling correction and speech synthesis (TTS) in an easy to use and extend way.

Table of Contents
-----------------

[](#table-of-contents)

- [General Information](#phpolyglot)
    - [Features](#features)
    - [Requirements](#requirements)
    - [Installation](#installation)
- [Basic Usage](#basic-usage)
    - [Translation](#translation)
        - [Yandex Translate API](#yandex-translate-api)
    - [Dictionary Lookup](#dictionary-lookup)
        - [Yandex Dictionary API](#yandex-dictionary-api)
    - [Spelling Check](#spelling-check)
        - [Yandex Speller API](#yandex-speller-api)
    - [Speech Synthesis](#speech-synthesis)
        - [IBM Watson Text-to-Speech](#ibm-watson-text-to-speech)
- [Possible ToDos](#possible-todos)
- [Useful Tools](#useful-tools)
    - [Running Tests](#running-tests)
    - [Code Sniffer Tool](#code-sniffer-tool)
    - [Code Auto-fixer](#code-auto-fixer)
    - [Building Docs](#building-docs)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [License](#license)
- [Notes](#notes)

Features
--------

[](#features)

- provides an easy-to-use way to utilise different language-related APIs for translation, grammar correction, TTS, etc.;
- custom APIs can be easily added, because the package heavily relies on implementation of different interfaces, therefore it is easy to plug-in (pull requests are appreciated);
- open or free (possibly with limitations) APIs are preferred;
- language codes must be [ISO-639](https://www.loc.gov/standards/iso639-2/php/code_list.php) compatible (alpha-2 or alpha-3 if there's no alpha-2);
- third-party APIs may contain their own limitations or licensing requirements (see [License](#license))

Requirements
------------

[](#requirements)

- PHP &gt;= 7.1;
- credentials for Yandex Translate API, Yandex Dictionary API and IBM Watson API (depending on what you are going to use).

Installation
------------

[](#installation)

```
composer require gino-pane/phpolyglot

```

Create a copy of `.env.example` file, name it `.env` and put your own API credentials in it. File contains links to pages which may be related to required credentials.

> In order to run examples from [examples](https://github.com/GinoPane/PHPolyglot/blob/master/examples) directory you have to specify your own valid API credentials.

Basic Usage
===========

[](#basic-usage)

The package contains a plenty of ready-to-use examples in [examples](https://github.com/GinoPane/PHPolyglot/blob/master/examples) directory. All endpoints either return a valid response or throws a relevant exception. All APIs are configured through [config.php](https://github.com/GinoPane/PHPolyglot/blob/master/config.php) file which contains the default API classes mapping. Support of dynamic configs was added in [1.1.0](https://github.com/GinoPane/PHPolyglot/releases/tag/v1.1.0) update:

```
$phpolyglot = new PHPolyglot($config, $env);
```

This allows you to pass your own configuration values if you don't want to rely on those that are stored in configuration files.

Translation
-----------

[](#translation)

There are two endpoints. For a single string:

```
function translate(string $text, string $languageTo, string $languageFrom = ''): TranslateResponse
```

and for multiple strings:

```
function translateBulk(array $text, string $languageTo, string $languageFrom = ''): TranslateResponse
```

As a minimum example you can pass text and language to translate into (source language will be detected by API):

```
$response = (new PHPolyglot())->translate('Hello world', 'it')->getTranslations(); // [ 0 => Ciao mondo ]
```

`TranslateResponse` has `getTranslations` method which returns an array of translations.

Supported languages may vary depending on third-party API.

### Yandex Translate API

[](#yandex-translate-api)

Please check the [list of supported languages](https://tech.yandex.com/translate/doc/dg/concepts/api-overview-docpage/#languages). [Yandex Translate API](https://tech.yandex.com/translate/doc/dg/concepts/api-overview-docpage/) is free to use with [limitations](https://translate.yandex.com/developers/prices) (1000 000 characters per day, up to 10 000 000 per month). If you want you can get a paid plan of course. The API won't let you to get into paid plan automatically, it will simply return an error when the limit is reached. In order to use the API you need to get the valid [API key](https://tech.yandex.com/keys/?service=trnsl).

Dictionary Lookup
-----------------

[](#dictionary-lookup)

There is a single endpoint, which can be used in two different forms.

For a lookup within the same language (get word forms):

```
function lookup(string $text, string $languageFrom): DictionaryResponse
```

and for translation-with-lookup (get multiple translations and additional information including word forms, examples, meanings, synonyms, transcription, etc.):

```
function lookup(string $text, string $languageFrom, string $languageTo): DictionaryResponse
```

As a minimum example you can pass text and its source language:

```
$response = (new PHPolyglot)->lookup('Hello', 'en)->getEntries();

$synonyms = implode(", ", $response[0]->getSynonyms());

$output = getTranscription()}

Main alternative: {$response[0]->getTextTo()}
Synonyms: {$synonyms}
TEXT

echo $output

/**
Initial word: hello

Part of speech: noun
Transcription: ˈheˈləʊ

Main alternative: hi
Synonyms: hallo, salut
*/
```

Supported languages may vary depending on third-party API.

### Yandex Dictionary API

[](#yandex-dictionary-api)

Please check the [list of supported languages](https://tech.yandex.com/dictionary/doc/dg/reference/getLangs-docpage/). [Yandex Dictionary API](https://tech.yandex.com/dictionary/doc/dg/concepts/api-overview-docpage/) is free to use with [limitations](https://yandex.com/legal/dictionary_api/?lang=en) (up to 10 000 references per day). In order to use the API you need to get the valid [API key](https://tech.yandex.com/keys/?service=dict).

Spelling Check
--------------

[](#spelling-check)

There are two endpoints. For a single string:

```
function spellCheck(string $text, string $languageFrom = ''): SpellCheckResponse
```

and for multiple strings:

```
function spellCheckBulk(array $texts, string $languageFrom = ''): SpellCheckResponse
```

As a minimum example you can pass only a text to check:

```
$corrections = $phpolyglot->spellCheckText('Helo werld', $languageFrom)->getCorrections();

/**
array(1) {
  [0] =>
  array(2) {
    'Helo' =>
    array(1) {
      [0] =>
      string(5) "Hello"
    }
    'werld' =>
    array(1) {
      [0] =>
      string(5) "world"
    }
  }
}
*/
```

Supported languages may vary depending on third-party API.

### Yandex Speller API

[](#yandex-speller-api)

Please check the [list of supported languages](https://tech.yandex.ru/speller/doc/dg/concepts/speller-overview-docpage/) (basically, only English, Russian and Ukrainian are supported at the moment). [Yandex Speller API](https://tech.yandex.ru/speller/doc/dg/concepts/api-overview-docpage/) is free to use with [limitations](https://yandex.ru/legal/speller_api/) (up to 10 000 calls/10 000 000 characters per day). No keys are required.

Speech Synthesis
----------------

[](#speech-synthesis)

The main endpoint is `PHPolyglot`'s `speak` method:

```
public function speak(
    string $text,
    string $languageFrom,
    string $audioFormat = TtsAudioFormat::AUDIO_MP3,
    array $additionalData = []
): TtsResponse
```

Only two parameters are required - text for synthesis `$text` and its source language `$languageFrom`.

Optional parameters `$audioFormat` and `$additionalData` may be omitted. Audio format allows to explicitly specify the required audio format of returned audio. Additional data allows to set API specific parameters for more precise results (voice, pitch, speed, etc.).

The list of audio formats which are currently recognized:

- TtsAudioFormat::AUDIO\_BASIC
- TtsAudioFormat::AUDIO\_FLAC
- TtsAudioFormat::AUDIO\_L16
- TtsAudioFormat::AUDIO\_MP3
- TtsAudioFormat::AUDIO\_MPEG
- TtsAudioFormat::AUDIO\_MULAW
- TtsAudioFormat::AUDIO\_OGG
- TtsAudioFormat::AUDIO\_WAV
- TtsAudioFormat::AUDIO\_WEBM

Please note that not all of them may be supported by your API of choice.

The TTS method returns `TtsResponse` which has `storeFile` method to store generated file with required name and extension into the specified directory (or by using default values):

```
function storeFile(string $fileName = '', string $extension = '', string $directory = ''): string
```

By default the file name is a simple `md5` hash of `$text` that was used for TTS, `$extension` is being populated based on `content-type` header (at least, for IBM Watson API), `$directory` is based on config setting.

```
(new PHPolyglot())->speak('Hello world', 'en')->storeFile(); // stores 3e25960a79dbc69b674cd4ec67a72c62.mp3
```

### IBM Watson Text-to-Speech

[](#ibm-watson-text-to-speech)

Please check the [list of supported languages and voices](https://console.bluemix.net/docs/services/text-to-speech/http.html#voices). IBM Watson TTS requires API credentials for authorization. Create your TTS project [there](https://www.ibm.com/watson/services/text-to-speech/) and get your API-specific credentials. API is free to use with limitations (up to 10 000 characters per month).

Possible ToDos
==============

[](#possible-todos)

- transcribe words;
- get synonyms, antonyms, derivatives;
- detect text language;
- add more configuration flexibility (choose API based on config constraints, like different APIs for different languages).

Useful Tools
============

[](#useful-tools)

Running Tests:
--------------

[](#running-tests)

```
php vendor/bin/phpunit

```

or

```
composer test

```

Code Sniffer Tool:
------------------

[](#code-sniffer-tool)

```
php vendor/bin/phpcs --standard=PSR2 src/

```

or

```
composer psr2check

```

Code Auto-fixer:
----------------

[](#code-auto-fixer)

```
php vendor/bin/phpcbf --standard=PSR2 src/

```

or

```
composer psr2autofix

```

Building Docs:
--------------

[](#building-docs)

```
php vendor/bin/phpdoc -d "src" -t "docs"

```

or

```
composer docs

```

Changelog
=========

[](#changelog)

To keep track, please refer to [CHANGELOG.md](https://github.com/GinoPane/PHPolyglot/blob/master/CHANGELOG.md).

Contributing
============

[](#contributing)

1. Fork it;
2. Create your feature branch (git checkout -b my-new-feature);
3. Make your changes;
4. Run the tests, adding new ones for your own code if necessary (phpunit);
5. Commit your changes (git commit -am 'Added some feature');
6. Push to the branch (git push origin my-new-feature);
7. Create new pull request.

Also please refer to [CONTRIBUTING.md](https://github.com/GinoPane/PHPolyglot/blob/master/CONTRIBUTING.md).

License
=======

[](#license)

Please refer to [LICENSE](https://github.com/GinoPane/PHPolyglot/blob/master/LICENSE).

> The [PHPolyglot](https://github.com/GinoPane/PHPolyglot) does not own any of results that APIs may return. Also, APIs may have their own rules about data usage, so beware of them when you use them.

Notes
=====

[](#notes)

Powered by [composer-package-template](https://github.com/GinoPane/composer-package-template) and [PHP Nano Rest](https://github.com/GinoPane/php-nano-rest).

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~18 days

Total

5

Last Release

3057d ago

Major Versions

v0.1 → v1.0.02018-01-31

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3897579?v=4)[Siarhei Karavai](/maintainers/GinoPane)[@GinoPane](https://github.com/GinoPane)

---

Tags

ibm-watsonphp-libraryphp71spellingtext-to-speechtranslationttsyandex-translatetranslationspellingtext-to-speechttsyandex translate apiibm watson ttsyandex apispelling correctionibm watson apigrammar correctionyandex dictionary api

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/gino-pane-phpolyglot/health.svg)

```
[![Health](https://phpackages.com/badges/gino-pane-phpolyglot/health.svg)](https://phpackages.com/packages/gino-pane-phpolyglot)
```

###  Alternatives

[gettext/gettext

PHP gettext manager

70231.8M115](/packages/gettext-gettext)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[om/potrans

Command line tool for translate Gettext with Google Translator API or DeepL API

10518.6k7](/packages/om-potrans)[inpsyde/multilingual-press

Simply THE multisite-based free open source plugin for your multilingual websites.

2414.0k1](/packages/inpsyde-multilingual-press)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
