Get To Know Mirza Yandex Translator For Laravel
Tags: webdev, opensource, php, laravel
Published: 2018-12-14 08:18:52

---
title: Get To Know Mirza Yandex Translator For Laravel
published: true
description: Mirza Translator For Laravel gives you the ability to easily translate and manipulate text using the Yandex.Translate API.
tags: webdev,opensource,php,laravel
---
Well, this is my first Laravel Package! :D

This package uses the Yandex.Translate API to translate text and provides several methods to make it easier to use the API!

Repo URL: [https://github.com/yak0d3/Mirza\_Yandex\_Translator](https://github.com/yak0d3/Mirza_Yandex_Translator)

Feedback is very appreciated!

# Methods Table

|Method|Parameters|Returns|Throws|Description|
|:-|:-|:-|:-|:-|
|translate|`string $text` `string $lang` *Optional:*  `string $format \[html or 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:*** <br>1. If target language is not supported.<br>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) <br> ***Note:*** If `$assoc` is set to `true`, the returned json string will have the same index names|
|detectLanguage|`string $text`  *Optional:* `bool $langName`|String|***Exception:***  1. If language code is not found.  2. If language name is not found|Detects 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 functions|Returns a `json string` containing the list of all supported languages|
|translateToAll|`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 <a href="#">`@yandex_rights`</a>. <br> ***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` `<select>` tag with the list of all available languages. <br> Also called via `blade` directive <a href="#">`@languages_select` </a>|

# Blade Directives Table

|Directive|Parameters|Description|
|:-|:-|:-|
|`@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` `<select>` tag with the list of all available languages.|
|`@translate`|`string $text`                    `string $lang`|Translate a given `$text` string to a given `$lang` (language)|

&#x200B;