-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[2.2] [FrameworkBundle][Translation] Added logging capability to translator #3890
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,10 @@ | |
|
||
use Symfony\Component\Translation\Translator as BaseTranslator; | ||
use Symfony\Component\Translation\MessageSelector; | ||
use Symfony\Component\Translation\MessageCatalogueInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\Config\ConfigCache; | ||
use Symfony\Component\HttpKernel\Log\LoggerInterface; | ||
|
||
/** | ||
* Translator. | ||
|
@@ -26,6 +28,7 @@ class Translator extends BaseTranslator | |
protected $container; | ||
protected $options; | ||
protected $loaderIds; | ||
protected $logger; | ||
|
||
/** | ||
* Constructor. | ||
|
@@ -44,6 +47,7 @@ public function __construct(ContainerInterface $container, MessageSelector $sele | |
{ | ||
$this->container = $container; | ||
$this->loaderIds = $loaderIds; | ||
$this->logger = null; | ||
|
||
$this->options = array( | ||
'cache_dir' => null, | ||
|
@@ -72,6 +76,27 @@ public function getLocale() | |
return $this->locale; | ||
} | ||
|
||
public function setLogger(LoggerInterface $logger) | ||
{ | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function validateCatalogueForId(MessageCatalogueInterface $catalogue, $id, $domain) | ||
{ | ||
if (null !== $this->logger && !$catalogue->defines($id, $domain)) { | ||
if ($catalogue->has($id, $domain)) { | ||
$this->logger->notice('Translator: using fallback catalogue.', array('id' => $id, 'domain' => $domain)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @meandmymonkey Thanks for making this PR. I know that a lot of time passed but could you also pass locale ( |
||
} else { | ||
$this->logger->warn('Translator: translation not found.', array('id' => $id, 'domain' => $domain)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
} | ||
} | ||
|
||
return parent::validateCatalogueForId($catalogue, $id, $domain); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should simply be named
logging
to be consistent with DoctrineBundleThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fast as always :)
done.