Google\Cloud\Translate\TranslateClient::detectLanguageBatch PHP Method

detectLanguageBatch() public method

Example: $results = $translate->detectLanguageBatch([ 'Hello World!', 'My name is David.' ]); foreach ($results as $result) { echo $result['languageCode']; }
See also: https://cloud.google.com/translate/v2/detecting-language-with-rest Detecting Langauge
public detectLanguageBatch ( array $strings, array $options = [] ) : array
$strings array
$options array [optional] { Configuration Options. @type string $format Indicates whether the string is either plain-text or HTML. Acceptable values are `html` or `text`. **Defaults to** `"html"`. }
return array A set of results. Each result includes a `languageCode` key containing the detected ISO 639-1 language code, an `input` key containing the original string, and in most cases a `confidence` key containing a value between 0 - 1 signifying the confidence of the result.
    public function detectLanguageBatch(array $strings, array $options = [])
    {
        $response = $this->connection->listDetections($options + ['q' => $strings, 'key' => $this->key]);
        $detections = [];
        foreach ($response['data']['detections'] as $key => $detection) {
            $detection = $detection[0];
            $detections[] = array_filter(['languageCode' => $detection['language'], 'input' => $strings[$key], 'confidence' => isset($detection['confidence']) ? $detection['confidence'] : null]);
        }
        return $detections;
    }