Skip to content

Commit

Permalink
translating absolute message with domain is not supported exception
Browse files Browse the repository at this point in the history
[Fixes #127]
  • Loading branch information
fprochazka committed May 16, 2017
1 parent 044b093 commit 00f555f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Kdyby/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
11 changes: 11 additions & 0 deletions tests/KdybyTests/Translation/Translator.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 00f555f

Please sign in to comment.