Skip to content

Commit

Permalink
Merge eefc004 into 7addf5d
Browse files Browse the repository at this point in the history
  • Loading branch information
haltuf committed Aug 22, 2019
2 parents 7addf5d + eefc004 commit 9cdf552
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ public function translate($message, ...$arg): string
$domain = isset($arg[2]) ? $arg[2] : NULL;
$locale = isset($arg[3]) ? $arg[3] : NULL;

if (is_array($count)) {
$locale = ($domain !== NULL) ? (string) $domain : NULL;
$domain = ($parameters !== NULL && !empty($parameters)) ? (string) $parameters : NULL;
$parameters = $count;
$count = NULL;
}

if (empty($message)) {
return $message;

Expand Down
11 changes: 11 additions & 0 deletions tests/KdybyTests/Translation/PrefixedTranslatorTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ class PrefixedTranslatorTest extends \KdybyTests\Translation\TestCase
Assert::same('Use 5 credits', $prefixed->translate(new Phrase('//front.orderForm.useCredits', 5)));
}

/**
* Reported at https://github.com/Kdyby/Translation/commit/7858654f4e68a932b09e9515996036ac44339362
*/
public function testBugRemovedUnnecessaryCode()
{
$translator = $this->createTranslator();
$prefixed = $translator->domain('front.homepage');

Assert::same('Hello world', $prefixed->translate('namedHello', ['name' => 'world']));
}

}

(new PrefixedTranslatorTest())->run();
10 changes: 10 additions & 0 deletions tests/KdybyTests/Translation/TranslatorTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ class TranslatorTest extends \KdybyTests\Translation\TestCase
}, \Kdyby\Translation\InvalidArgumentException::class, 'Providing domain "front" while also having the message "//homepage.hello" absolute is not supported');
}

/**
* Reported at https://github.com/Kdyby/Translation/commit/7858654f4e68a932b09e9515996036ac44339362
*/
public function testBugRemovedUnnecessaryCode()
{
$translator = $this->createTranslator();

Assert::same('Hello world', $translator->translate('Hello %value%', ['value' => 'world']));
}

}

(new TranslatorTest())->run();

0 comments on commit 9cdf552

Please sign in to comment.