Translate/Method/Translator.php
public function translate($query, $target, $source = null, $economic = false, $plainText = false)
    {
        if (!is_array($query)) {
            return $this->handle($query, $target, $source, $plainText);
        }

        if ($economic) {
            $results = $this->handle(implode(self::ECONOMIC_DELIMITER, $query), $target, $source, $plainText);
            $results = explode(self::ECONOMIC_DELIMITER, $results);

            return array_map('trim', $results);
        }

        $results = [];

        foreach ($query as $item) {
            $results[] = $this->handle($item, $target, $source, $plainText);
        }

        return $results;
    }
public function translate($query, $target, $source = null, $economic = false, $plainText = false)
    {
        if (!is_array($query)) {
            return $this->handle($query, $target, $source, $plainText);
        }

        if ($economic) {
            $results = $this->handle(implode(self::ECONOMIC_DELIMITER, $query), $target, $source, $plainText);
            $results = explode(self::ECONOMIC_DELIMITER, $results);

            return array_map('trim', $results);
        }

        $results = [];

        foreach ($query as $item) {
            $results[] = $this->handle($item, $target, $source, $plainText);
        }

        return $results;
    }
public function translate ( $ query , $ target , $ source = null , $ economic = false , $ plainText = false ) { if ( ! is_array ( $ query ) ) { return $ this -> handle ( $ query , $ target , $ source , $ plainText ) ; } if ( $ economic ) { $ results = $ this -> handle ( implode ( self :: ECONOMIC_DELIMITER , $ query ) , $ target , $ source , $ plainText ) ; $ results = explode ( self :: ECONOMIC_DELIMITER , $ results ) ; return array_map ( 'trim' , $ results ) ; } $ results = [ ] ; foreach ( $ query as $ item ) { $ results [ ] = $ this -> handle ( $ item , $ target , $ source , $ plainText ) ; } return $ results ; }
Translates given string in given target language from a source language via the Google Translate API.
If source language is not defined, it use detector method to detect string language.

@param string|array $query     A query string to translate
@param string       $target    A target language
@param string       $source    A source language
@param bool         $economic  Enable the economic mode? (only 1 request)
@param bool         $plainText The source (and response) are plain text

@return array|string
Translates given string in given target language from a source language via the Google Translate API . If source language is not defined it use detector method to detect string language .