8000 [Translation] added LoggingTranslator. by aitboudad · Pull Request #10887 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Translation] added LoggingTranslator. #10887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Prev Previous commit
Next Next commit
[Translation][LoggableTranslator] make logger required with Minor fix.
  • Loading branch information
aitboudad committed Sep 24, 2014
commit 0f2294dcefe8b7e8181deeedc269bc79f5a435ed
12 changes: 6 additions & 6 deletions src/Symfony/Component/Translation/LoggableTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LoggableTranslator implements TranslatorInterface
* @param Translator $translator The translator
* @param LoggerInterface $logger A logger instance
*/
public function __construct(Translator $translator, LoggerInterface $logger = null)
public function __construct(Translator $translator, LoggerInterface $logger)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is unfortunate that we have to wrap the Translator implementation rather than any TranslatorInterface, as getCatalogue is not part of the interface. This would make it more complex to have several bundles register decorators on the translator

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we need another interface containing getCatalogue. what do you think @fabpot ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, adding another interface is what we"ve done in other places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it must be in another PR,
what should we name it? TranslationBagInterface

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @fabpot , @stof

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aitboudad It should be done in this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, you also need to update the type hint here, probably by removing it and checking that the passed object implements both interfaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I check the passed object implements both interfaces, I think it will produce a BC break !!

{
$this->translator = $translator;
$this->logger = $logger;
Expand Down Expand Up @@ -89,11 +89,11 @@ public function __call($method, $args)
}

/**
* Logs for missing catalogue.
* Logs for missing translations.
*
* @param string $id
* @param string $domain
* @param string $locale
* @param string $id
* @param string|null $domain
* @param string|null $locale
*/
private function log($id, $domain, $locale)
{
Expand All @@ -107,7 +107,7 @@ private function log($id, $domain, $locale)

$id = (string) $id;
$catalogue = $this->translator->getCatalogue($locale);
if (null === $this->logger || $catalogue->defines($id, $domain)) {
if ($catalogue->defines($id, $domain)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@

class LoggableTranslatorTest extends \PHPUnit_Framework_TestCase
{
public function testTransWithNoTranslationIsLogged()
protected function setUp()
{
if (!interface_exists('Psr\Log\LoggerInterface')) {
$this->markTestSkipped('The "LoggerInterface" is not available');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to put this check in setUp

}

public function testTransWithNoTranslationIsLogged()
{
$logger = $this->getMock('Psr\Log\LoggerInterface');
$logger->expects($this->exactly(2))
->method('warning')
Expand All @@ -37,10 +40,6 @@ public function testTransWithNoTranslationIsLogged()

public function testTransChoiceFallbackIsLogged()
{
if (!interface_exists('Psr\Log\LoggerInterface')) {
$this->markTestSkipped('The "LoggerInterface" is not available');
}

$logger = $this->getMock('Psr\Log\LoggerInterface');
$logger->expects($this->once())
->method('debug')
Expand Down
0