diff --git a/src/Kdyby/Translation/Translator.php b/src/Kdyby/Translation/Translator.php index d012b1f5..2a582619 100644 --- a/src/Kdyby/Translation/Translator.php +++ b/src/Kdyby/Translation/Translator.php @@ -158,6 +158,14 @@ public function translate($message, $count = NULL, $parameters = [], $domain = N } if (Strings::startsWith($message, '//')) { + if ($domain !== NULL) { + throw new InvalidArgumentException(sprintf( + 'Providing domain "%s" while also having the message "%s" absolute is not supported', + $domain, + $message + )); + } + $message = Strings::substring($message, 2); } diff --git a/tests/KdybyTests/Translation/Translator.phpt b/tests/KdybyTests/Translation/Translator.phpt index 2c0e5a4a..452f848d 100644 --- a/tests/KdybyTests/Translation/Translator.phpt +++ b/tests/KdybyTests/Translation/Translator.phpt @@ -158,6 +158,17 @@ class TranslatorTest extends TestCase Assert::same("Ahoj světe", $translator->translate('//front.homepage.hello')); } + + + public function testTranslatingAbsoluteMessageWithDomainIsNotSupported() + { + $translator = $this->createTranslator(); + + Assert::exception(function () use ($translator) { + $translator->translate('//homepage.hello', NULL, [], 'front'); + }, 'Kdyby\Translation\InvalidArgumentException', 'Providing domain "front" while also having the message "//homepage.hello" absolute is not supported'); + } + } (new TranslatorTest())->run();