Skip to content

Commit

Permalink
Omit model if not set (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpedrie authored and dwsupplee committed Feb 22, 2017
1 parent 4ac28cf commit 447fbed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/Translate/TranslateClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function translate($string, array $options = [])
* either plain-text or HTML. Acceptable values are `html` or
* `text`. **Defaults to** `"html"`.
* @type string $model The model to use for the translation request. May
* be `nmt` or `base`. **Defaults to** an empty string.
* be `nmt` or `base`. **Defaults to** null.
* }
* @return array A set of translation results. Each result includes a
* `source` key containing the detected or provided language of the
Expand All @@ -213,15 +213,19 @@ public function translate($string, array $options = [])
public function translateBatch(array $strings, array $options = [])
{
$options += [
'model' => '',
'model' => null,
];

$response = $this->connection->listTranslations($options + [
$options = array_filter($options + [
'q' => $strings,
'key' => $this->key,
'target' => $this->targetLanguage,
'model' => $options['model']
]);
], function ($opt) {
return !is_null($opt);
});

$response = $this->connection->listTranslations($options);

$translations = [];
$strings = array_values($strings);
Expand Down
20 changes: 19 additions & 1 deletion tests/unit/Translate/TranslateClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testWithNoKey()
$client = new TranslateTestClient();

$this->connection->listTranslations(Argument::that(function($args) {
if (!is_null($args['key'])) {
if (isset($args['key'])) {
return false;
}

Expand All @@ -53,6 +53,24 @@ public function testWithNoKey()
$client->translate('foo');
}

public function testTranslateModel()
{
$this->connection->listTranslations(Argument::that(function ($args) {
if (isset($args['model'])) return false;
}));

$this->client->setConnection($this->connection->reveal());

$this->client->translate('foo bar');

$this->connection->listTranslations(Argument::that(function ($args) {
if ($args['model'] !== 'base') return false;
}));

$this->client->setConnection($this->connection->reveal());
$this->client->translate('foo bar', ['model' => 'base']);
}

public function testTranslate()
{
$expected = $this->getTranslateExpectedData('translate', 'translated', 'en');
Expand Down

0 comments on commit 447fbed

Please sign in to comment.