diff --git a/src/Translator.php b/src/Translator.php index 002bdf6f..ea4d4ba4 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -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; diff --git a/tests/KdybyTests/Translation/PrefixedTranslatorTest.phpt b/tests/KdybyTests/Translation/PrefixedTranslatorTest.phpt index c3dfd9c2..6f9555f3 100644 --- a/tests/KdybyTests/Translation/PrefixedTranslatorTest.phpt +++ b/tests/KdybyTests/Translation/PrefixedTranslatorTest.phpt @@ -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(); diff --git a/tests/KdybyTests/Translation/TranslatorTest.phpt b/tests/KdybyTests/Translation/TranslatorTest.phpt index 308beadf..97f54c49 100644 --- a/tests/KdybyTests/Translation/TranslatorTest.phpt +++ b/tests/KdybyTests/Translation/TranslatorTest.phpt @@ -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();