/**
* Detect the language of multiple strings.
*
* Example:
* ```
* $results = $translate->detectLanguageBatch([
* 'Hello World!',
* 'My name is David.'
* ]);
*
* foreach ($results as $result) {
* echo $result['languageCode'];
* }
* ```
*
* @see https://cloud.google.com/translate/v2/detecting-language-with-rest Detecting Langauge
*
* @param string $string The string to detect the language of.
* @param array $options [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;
}