Download the PHP package yak0d3/mirza_yandex_translator without Composer

On this page you can find all versions of the php package yak0d3/mirza_yandex_translator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mirza_yandex_translator

Mirza Yandex Translator Logo

build Dependencies Code Quality

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

  1. Quick Start
  2. Quick Usage Guide
  3. Documentation
  4. Methods
  5. Blade Directives
  6. Issues & Suggestions
  7. License

Quick Start

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

Note: You can get your FREE API Key from the Yandex.Translate Developers Dashboard

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 directives sections to view the list of available blade directives.

Note: You can decode this string by using the json_decode function.

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

Note: You can decode this string by using the json_decode function.

Still not getting it? Take a look at the Documentation below and the confusion will go away!

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
    1. The translateArray method
      1. Using sequential arrays
      2. Using associative arrays
    2. The translateTo method
    3. The detectLanguage method
      1. Return language code
      2. Return language name
    4. The getSupportedLanguages method
    5. The translateToAll method
    6. Blade directives
      1. @translate directive
      2. @yandex_rights directive
      3. @languages_select directive

        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:

2. The translateArray method

Note that all json strings needs to be decoded using the PHP json_decode 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:

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:

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:

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:

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

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:

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:

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:

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

Let's decode this json string and play a little bit!

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:

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 function

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:

7. Blade Directives

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.

Method Parameters Returns Throws Description
translate 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 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 Yandex Translate: Requirements for the use of translation results 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.
Also called via blade directive @languages_select

Blade Directives

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)

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.

License

Mirza Yandex Translator MIT License

All versions of mirza_yandex_translator with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package yak0d3/mirza_yandex_translator contains the following files

Loading the files please wait ....