PHPackages                             yak0d3/mirza\_yandex\_translator - 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. yak0d3/mirza\_yandex\_translator

ActiveLibrary

yak0d3/mirza\_yandex\_translator
================================

Mirza Translator For Laravel gives you the ability to easily translate and manipulate text using the Yandex.Translate API.

v1.0.1(7y ago)132832MITPHP

Since Dec 13Pushed 7y ago1 watchersCompare

[ Source](https://github.com/yak0d3/Mirza_Yandex_Translator)[ Packagist](https://packagist.org/packages/yak0d3/mirza_yandex_translator)[ RSS](/packages/yak0d3-mirza-yandex-translator/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)Dependencies (1)Versions (4)Used By (0)

[![Mirza Yandex Translator Logo](https://camo.githubusercontent.com/4f8031a99b7079817502d4e1b41bea66a9ecfd0d6251b27d83d485d1909f6345/68747470733a2f2f692e696d6775722e636f6d2f446c6752686b4e2e706e67)](https://camo.githubusercontent.com/4f8031a99b7079817502d4e1b41bea66a9ecfd0d6251b27d83d485d1909f6345/68747470733a2f2f692e696d6775722e636f6d2f446c6752686b4e2e706e67)

 [![build](https://camo.githubusercontent.com/f9d625a832dd9e30df9a56f11343af099ec7bbacfa1fe1eb60e3cc5d0e489d03/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f79616b3064332f4d69727a615f59616e6465785f5472616e736c61746f722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/yak0d3/Mirza_Yandex_Translator) [![](https://camo.githubusercontent.com/85ac0a50efae1c4d7546dcb538117c4b21675170a91ed08fd2720466ef6ffe25/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3136313632323235392f736869656c64)](https://github.styleci.io/repos/161622259) [![Dependencies](https://camo.githubusercontent.com/0713681ff50430dee4605816c2fa7d976e94467e65d7dbebd09334ae770e087e/68747470733a2f2f696d672e736869656c64732e696f2f6c6962726172696573696f2f6769746875622f79616b3064332f4d69727a615f59616e6465785f5472616e736c61746f722e7376673f7374796c653d666c61742d737175617265)](https://github.com/yak0d3/Mirza_Yandex_Translator) [![Code Quality](https://camo.githubusercontent.com/ad3d083d391f0f37286c0c9601f54f347faeddf7a823828e7c8d302a4b71f3df/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f79616b3064332f4d69727a615f59616e6465785f5472616e736c61746f722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/yak0d3/Mirza_Yandex_Translator/) [![](https://camo.githubusercontent.com/86f880e84e91dcb86e181722c1257b3d6691ec12b3b3afc7aae43ceb277418d0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f79616b3064332f4d69727a615f59616e6465785f5472616e736c61746f722e7376673f7374796c653d666c61742d737175617265)](https://github.com/yak0d3/Mirza_Yandex_Translator/releases) [![](https://camo.githubusercontent.com/22dd4fcb552b15a2684d70b0652289e7d4041222b8a85ce5fd0bd58f87b4d287/68747470733a2f2f706f7365722e707567782e6f72672f79616b3064332f6d69727a615f79616e6465785f7472616e736c61746f722f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://github.com/yak0d3/Mirza_Yandex_Translator/blob/master/LICENSE)

Mirza Yandex Translator For Laravel
-----------------------------------

[](#mirza-yandex-translator-for-laravel)

> ***Mirza Translator*** gives you the ability to easily translate and manipulate text using the Yandex.Translate API.

Table Of Contents
-----------------

[](#table-of-contents)

1. [ Quick Start](#quick-start)
2. [ Quick Usage Guide](#quick-usage-guide)
3. [ Documentation](#docs)
4. [ Methods](#methods)
5. [ Blade Directives](#blade-directives)
6. [ Issues &amp; Suggestions](#IssuesAndSuggestions)
7. [ License](#license)

Quick Start
-----------

[](#quick-start)

Let's set this up real quick in *just* three mere steps!

- Navigate to your Laravel installation folder via the terminal/cmd and run `composer require yak0d3/Mirza_Yandex_Translator` or add `"yak0d3/Mirza_Yandex_Translator": "^1.0.0"` manually to your `composer.json`.
- Publish the configuration file using one of the following methods:

    1. Run `php artisan vendor:publish --provider="yak0d3\Mirza_Yandex_TranslatorT\MirzaServiceProvider"`
    2. Run `php artisan vendor:publish` and type the number behind `yak0d3\Mirza_Yandex_TranslatorT\MirzaServiceProvider` then press `Enter`[![Publish configuration using php artisan vendor:publish](https://camo.githubusercontent.com/3da3fc3e605f336bc701b796ecb969e27da9c004b648375d00b3f012a10d648d/68747470733a2f2f692e696d6775722e636f6d2f50677873526a492e676966)](https://camo.githubusercontent.com/3da3fc3e605f336bc701b796ecb969e27da9c004b648375d00b3f012a10d648d/68747470733a2f2f692e696d6775722e636f6d2f50677873526a492e676966)
- Add environment variable to your `.env` file with the name `YANDEX_API` and set its value to your own Yandex.Translate API Key. (***e.g.*** `YANDEX_API=MY_YANDEX_API_KEY`)

> ***Note***: *You can get your FREE API Key from the [Yandex.Translate Developers Dashboard](https://translate.yandex.com/developers/keys)*

 Quick Usage Guide
-------------------

[](#-quick-usage-guide-)

The *quick usage guide* is only meant to explain the basic usage of this package, for the list of methods and its relative information (Parameters, Return Type etc..) jump to the [methods section](#) or jump to the [directives sections](#) to view the list of available `blade` directives.

- #### Detect Language:
     `Mirza::detectLanguage('Welcome');`
     *Output:* `en`

    [](#detect-language--mirzadetectlanguagewelcome--output-en)
- #### Translate text:
     `Mirza::translate('Hello','es');`
     *Output:* `"Hola"`

    [](#translate-text---mirzatranslatehelloes--output-hola)
- #### Translate to Multiple Languages:
     `Mirza::translateTo('Hello World!',['es', 'tr', 'fr']')`

    *Output:*

    [](#translate-to-multiple-languages--mirzatranslatetohello-worldes-tr-fr--output)

    ```
     {
      "originalText": "Hello World!",
      "originalLanguage": "en",
      "text": {
      "es": "Hola Mundo!",
      "tr": "Merhaba D\u00fcnya!",
      "fr": "Bonjour Tout Le Monde!"
      }
     }
    ```

> ***Note:*** *You can decode this string by using the [`json_decode`](http://https://php.net/manual/en/function.json-decode.php) function.*

- #### Translate an Array of Text:
     `$textArray = ['Hello','My Dear','Friend'];`
     `Mirza::translateArray($textArray,'fr');`
     *Output:*

    [](#translate-an-array-of-text--textarray--hellomy-dearfriend-mirzatranslatearraytextarrayfr--output)

```
[
 {
 "originalText": "Hello",
 "translatedText": "Bonjour"
 },
 {
 "originalText": "My dear",
 "translatedText": "Mon cher"
 },
 {
 "originalText": "Friend",
 "translatedText": "Ami"
 }
]
```

> ***Note:*** *You can decode this string by using the [`json_decode`](http://https://php.net/manual/en/function.json-decode.php) function.*

Still not getting it? Take a look at the [Documentation](#docs) below and the confusion will go away!

 Documentation (With Examples)
------------------------------

[](#-documentation--with-examples)

Let's admin it, not everyone in here will find it easy to start using this package, so let's try to understand what's happening together. This section will cover the usage of each and every method provided by *Mirza Yandex Translator*, here is the table of contents:

1. [The `translate` method](#docs-translate)
2. [The `translateArray` method](#docs-translateArray)
    1. [Using sequential arrays](#docs-translateArray-sequential)
    2. [Using associative arrays](#docs-translateArray-assoc)
3. [The `translateTo` method](#docs-translateTo)
4. [The `detectLanguage` method](#docs-detectLanguage)
    1. [Return language code](#docs-detectLanguage-code)
    2. [Return language name](#docs-detectLanguage-name)
5. [The `getSupportedLanguages` method](#docs-getSupportedLanguages)
6. [The `translateToAll` method](#docs-translateToAll)
7. [Blade directives](#docs-blade-directives)
    1. [`@translate` directive](#docs-directives-translate)
    2. [`@yandex_rights` directive](#docs-directives-rights)
    3. [`@languages_select` directive](#docs-directives-select)

 1. **The `translate` method**

As you have already expected, for sure there is a `translate` method for a translator package, this method takes two parameters; the text and the ISO code of the target language. ***Example:***

```
	$es_translation = Mirza::translate('Hello World!', 'es); //The first param is the text, the second one is the ISO code of the language
	echo $es_translation; //This will output "Hola Mundo!"
```

2. **The `translateArray` method**

> ***Note*** that all `json` strings needs to be decoded using the PHP [`json_decode`](http://php.net/manual/en/function.json-decode.php) function. ***Tip:*** To return a PHP array set the second argument of `json_decode` to `true` (*e.g.* `json_decode($jsonString, true);` ).
> If you prefer manipulating `json objects`, leave the second argument empty or set it to `false`.

`Mirza::translateArray(['Hello', 'My Dear', 'Friend'],'fr');` this method translates a given array of text into which is in our case this array `['Hello', 'My Dear', 'Friend']` and translates it to a given language which is French in our example.
 This function returns a `json encoded` string like the following:

```
[
 {
 "originalText": "Hello",
 "translatedText": "Bonjour"
 },
 {
 "originalText": "My dear",
 "translatedText": "Mon cher"
 },
 {
 "originalText": "Friend",
 "translatedText": "Ami"
 }
]
```

As you can see, the output `json string` is in the same order of the input array, now we can access each of these elements by decoding the string like so:

```
	$jsonString = Mirza::translateArray(['Hello', 'My Dear', 'Friend'],'fr'); //The json string
	$translationsArray = json_decode($jsonString, true); //Our PHP Array
	$first_translation = $translationsArray[0]['translatedText'];
	$second_translation = $translationsArray[1]['translatedText'];
	$third_translation = $translationsArray[2]['translatedText'];
```

Easy, right? But it could get easier if you set the the $assoc parameter to true so you are able to access your string translations by their index names (that you have set manually). **No body** is getting confused in here, here is an example:

```
$textArray = [
	'header' => "Welcome to the Mirza Documentation Page",
	'body' => "The body is too long to be put in this item",
	'footer' => "Thank you for reading this!"
]; //Our associative text array
$jsonString = Marzi::translate($textArray,'es', true); //Notice that i have set $assoc (third param) to `true`
$translationsArray = json_decode($jsonString, true);
//Now you can access the translations by their old index names
	$header = $translationsArray['header']['translatedText'];
	$body = $translationsArray['body']['translatedText'];
	$footer = $translationsArray['footer']['translatedText'];
```

> **Note:** If you set `$assoc` to `true` and provide a sequential array an exception will be thrown.

3. **The `translateTo` method:**

This method is (maybe) the reverse version of the previous function, instead of taking an `array` of strings, this method takes one `string` and translates it to an array of languages. ***Example:***

```
	$jsonString = Mirza::translateTo('My awesome text', ['ar', 'tr', 'de']);
```

The above example will return `json string` with the following structure:

```
[
	{
		"originalText":"My awesome text",
		"originalLanguage": "en",
		"text":{
			"ar":"\u0628\u0644\u062f\u064a \u0627\u0644\u0646\u0635 \u0631\u0647\u064a\u0628\u0629",
			"tr":"M\u00fcthi\u015f metin",
			"de":"Meine wunderbare text"
		}

	}
]
```

> You may have noticed that some of the characters are in Unicode format, no worries if you `echo` it later on it will be displayed correctly.

Now we can easily decode this `json string` and access our data like so:

```
	$translations = json_decode($jsonString, true); //Our PHP array
	$originalText = $translations['originalText'];
	$originalLanguage = $translations['originalLanguage'];
	$ar_translation = $translations['text']['ar'];
	$tk_translation = $translations['text']['tr'];
	$de_translation = $translations['text']['de'];
```

4. **The `detectLanguage` method**

You sometimes need to detect in which language a text is written, the `detectLanguage` method is made just for this matter! As mentioned in the [methods table](#), this method takes one required parameter and one optional. The optional parameter (`boolean $name`) lets us switch between returning the language ISO code or the language name.

***Example:***

- Return language code:

```
//Leave the $name param empty or set it to `false`
//To return the language ISO code
$lang = Mirza::detectLanguage('Hello World!');
echo $lang; //Outputs "en"
```

- Return language name:

```
//Setthe $name param to `true`
//To return the language ISO code
$lang = Mirza::detectLanguage('Hello World!', true);
echo $lang; //Outputs "English"
```

5. **The `getSupportedLanguages` method**

This method takes no parameters (it should, but that will be added in a later version) and if executed it returns the list of all the supported languages.

***Example:***

```
//Save the json encoded string to the `$supportedLanguages` variable
$supportedLanguages = Mirza::getSupportedLanguages();
echo $supportedLanguages;
/* Outputs the json string in the following format:
	[
		{ 'lang_code' => 'lang_name' },
		{ 'lang_code' => 'lang_name' },
	]
*/
```

I didn't want to include the whole output because it is so long, but if you are still curious about it, i was prepared for this! Here is a screenshot: [![The list of supported Yandex.Translate languages](https://camo.githubusercontent.com/0dde0ea692cf346cf0e768f60736ea2206a38b484b99e8b5287c0eba3cd5ddf5/68747470733a2f2f692e696d6775722e636f6d2f72506d396f36752e706e67)](https://camo.githubusercontent.com/0dde0ea692cf346cf0e768f60736ea2206a38b484b99e8b5287c0eba3cd5ddf5/68747470733a2f2f692e696d6775722e636f6d2f72506d396f36752e706e67)

Let's [decode](https://http://php.net/manual/en/function.json-decode.php) this `json string` and play a little bit!

```
//Decode json string and wrap it into a PHP array
$langsArray = json_decode($supportedLanguages, true);
```

Let's say we have a language code, but we don't know to what language it refers, this line would help us a lot in such a case:

```
echo $langsArray['tr']; //Outputs "Turkish"
```

Now supposing that we have a language name, but we doesn't know the ISO code, *EASY PEASY!* We can do it with the PHP [`array_flip`](http://php.net/manual/en/function.array-flip.php) function

```
$flippedArray = array_flip($langsArray);
/* The values are now keys! Cool right? */
$languageCode = $flippedArray['Sinhalese'];
echo $languageCode; //Outputs "si"
```

6. **The `translateToAll` method**

I don't know what you might use this method for, but i thought it would be nice to include such a feature. As mentioned in the method name, this method translates a given string to all of the supported languages. ***Example:***

```
//Save the json string to a variable
$myStringInAllLanguages = Mirza::translateToAll('My string');
echo $myStringInAllLanguages;
/*Outputs a similar string to the `translateTo` method but
with all supported languages*/
```

7. **Blade Directives**

- `@translate`: Allows you to translate a given text to a given language on the go

    ***Example:***

    ```
     @translate('Welcome', 'fr')
    ```
- `@yandex_rights`: If you have read the [Yandex.Translate requirements for the use of translation results](#) you'd know that this directive will be very useful.
     You have to specify the `color` as the first argument and the `font-size` as the second one.

    ***Example:***

    ```
     	@yandex_rights('black', '16px');

     	Powered by Yandex.Translate
    ```

    - `@languages_select`: Generates an HTML `` with the list of all supported languages.

    ***Example:***

    ```
      @languages_select

     	Lang_Name
     	Lang_Name
     	Lang_Name

    ```

Methods
-------

[](#methods)

Everything in **Mirza** is meant to be easy and readable, just by taking a look at the *source code* you will understand what's happening in no time. But don't worry, i have saved you the struggle and made a table containing the the list of methods that ***Mirza Translator*** provides.

MethodParametersReturnsThrowsDescriptiontranslate`string $text`
`string $lang`
 *Optional:* `string $format [html|plain] (Default: "Plain")`String***Exception:*** If text couldn't be translated.Translates a given `$text` to a given `$lang` (language)translateTo`string $text`
 `array $langs`String (json)***Exception:*** If one or more languages aren't supported.Translate a given `$text` to multiple `$langs` (languages)translateArray`array $textArray`
 `string $lang`
 *Optional:* `bool $assoc (Default: false)`String (json)***Exception:***
1. If target language is not supported.
2. If `$assoc` is set to `true` and the given array is not associative.Translates a `$textArray` (array of text) to a given `$lang` (language)
 ***Note:*** If `$assoc` is set to `true`, the returned json string will have the same index namesdetectLanguage`string $text`
 *Optional:* `bool $langName`String***Exception:***
 1. If language code is not found.
 2. If language name is not foundDetects the language of a given `$text` and returns the language code
 ***Note:*** If `$langName` is set to `true`, the language full name will be returned instead.getSupportedLanguages*None*String (json)***Exception:*** If an unknown error occurs while trying to fetch the list of supported functionsReturns a json string containing the list of all supported languagestranslateToAll`string $text`String (json)*None*Translates a string (`$text`) to all supported languages.
 ***Note:*** This may take a while and cause a `PHP max_execution_time TIMEOUT Exception`yandex\_rights*Optional:* `string $color (Default: #fff)`
 `string $fontsize (Default: 14px) `String*None*Returns the string of the "Powered By Yandex.Translate" link string. Also called via `blade` directive [`@yandex_rights`](#).
 ***Note:*** Please refer to [Yandex Translate: Requirements for the use of translation results](https://tech.yandex.com/translate/doc/dg/concepts/design-requirements-docpage/) to know more about font-size, color and placing requirements.languages\_select*None*String*None*Returns the string of an `HTML` ` ` tag with the list of all available languages.
 Also called via `blade` directive [`@languages_select` ](#) Blade Directives
-----------------

[](#-blade-directives)

DirectiveParametersDescription`@yandex_rights`*Optional:* `string $color (Default: #fff)`
 `string $fontsize (Default: 14px) `Generates an HTML link for the "Powered By Yandex.Translate" text.`@languages_select`*None*Generates an `HTML` ` ` tag with the list of all available languages.`@translate``string $text`
 `string $lang`Translate a given `$text` string to a given `$lang` (language) Issues &amp; Suggestions
-------------------------

[](#-issues--suggestions)

***Mirza*** has been tested by only one person (obviously me 😃), which means that problems might occur with others, if something went wrong with your *Mirza* installation or you think something is still missing, please let me know by submitting a [new issue](https://github.com/yak0d3/Mirza_Yandex_Translator/issues/new).

 License
--------

[](#-license)

[![Mirza Yandex Translator MIT License](https://camo.githubusercontent.com/70e419721be171552f4c2d699c49bd10434fd3a759c14921934baade55978de8/68747470733a2f2f692e696d6775722e636f6d2f4e7870745573712e706e67)](https://camo.githubusercontent.com/70e419721be171552f4c2d699c49bd10434fd3a759c14921934baade55978de8/68747470733a2f2f692e696d6775722e636f6d2f4e7870745573712e706e67)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~29 days

Total

2

Last Release

2678d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f7991855cb00d8c378f7d1e33dca678b33d2d9ccfb52a33d1439d69859ad8c57?d=identicon)[yak0d3](/maintainers/yak0d3)

---

Top Contributors

[![yak0d3](https://avatars.githubusercontent.com/u/32985181?v=4)](https://github.com/yak0d3 "yak0d3 (6 commits)")

---

Tags

laravellaravel-5-packagelaravel-applicationlaravel-frameworklaravel-packagelaravel5laravel57phpphp-libraryphp7yandexyandex-apiyandex-translateyandex-translation-apilaravel-translatoryandex-translateyandex translate apilaravel yandex translateLaravel translation package

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/yak0d3-mirza-yandex-translator/health.svg)

```
[![Health](https://phpackages.com/badges/yak0d3-mirza-yandex-translator/health.svg)](https://phpackages.com/packages/yak0d3-mirza-yandex-translator)
```

###  Alternatives

[waavi/translation

A Translation package for Laravel 5 with database and cache support

367437.9k6](/packages/waavi-translation)[elegantly/laravel-translator

All on one translations management for Laravel

6216.9k](/packages/elegantly-laravel-translator)

PHPackages © 2026

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