diff --git a/src/Translate/TranslateClient.php b/src/Translate/TranslateClient.php index 111d671b65f0..086674a32e8e 100644 --- a/src/Translate/TranslateClient.php +++ b/src/Translate/TranslateClient.php @@ -224,6 +224,7 @@ public function translateBatch(array $strings, array $options = []) ]); $translations = []; + $strings = array_values($strings); if (isset($response['data']['translations'])) { foreach ($response['data']['translations'] as $key => $translation) { diff --git a/tests/unit/Translate/TranslateClientTest.php b/tests/unit/Translate/TranslateClientTest.php index 0f0eed833f7d..57efdcf25e01 100644 --- a/tests/unit/Translate/TranslateClientTest.php +++ b/tests/unit/Translate/TranslateClientTest.php @@ -140,6 +140,37 @@ public function testTranslateBatch() $this->assertEquals($expected2, $translations[1]); } + public function testTranslateBatchWithNotZeroIndexedInput() + { + $expected1 = $this->getTranslateExpectedData('translate', 'translated', 'en'); + $expected2 = $this->getTranslateExpectedData('translate2', 'translated2', 'en'); + $stringsToTranslate = [1 => $expected1['input'], 2 => $expected2['input']]; + + $target = 'de'; + $this->connection + ->listTranslations([ + 'target' => $target, + 'q' => $stringsToTranslate, + 'key' => $this->key, + 'model' => 'base' + ]) + ->willReturn([ + 'data' => [ + 'translations' => [ + $this->getTranslateApiData($expected1['text'], $expected1['source']), + $this->getTranslateApiData($expected2['text'], $expected2['source']) + ] + ] + ]) + ->shouldBeCalledTimes(1); + $client = new TranslateTestClient(['key' => $this->key, 'target' => $target]); + $client->setConnection($this->connection->reveal()); + $translations = $client->translateBatch($stringsToTranslate, ['model' => 'base']); + + $this->assertEquals($expected1, $translations[0]); + $this->assertEquals($expected2, $translations[1]); + } + public function testDetectLanguage() { $expected = $this->getDetectionExpectedData('text', 'en', .5);