-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
aitboudad
commented
May 10, 2014
Q | A |
---|---|
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #3015, #2435 |
License | MIT |
Doc PR | symfony/symfony-docs/pull/4050 |
} | ||
|
||
return $this->catalogues[$locale]; | ||
} |
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.
This would fix #2435. Might be worth to cover it by test.
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.
done
This is a much better approach than previous attempts to solve the problem. |
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* Translator. |
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.
Remove please.
* @param TranslatorInterface $translator The translator | ||
* @param LoggerInterface $logger A logger instance | ||
*/ | ||
public function __construct(TranslatorInterface $translator, LoggerInterface $logger = null) |
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.
the typehint is wrong. It expects getCatalogue
on the translator, which is not part of the interface
To enable logger in config (default value is %kernel.debug%): framework:
#esi: ~
translator: { fallback: "%locale%", logging: true } |
@@ -428,6 +428,7 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode) | |||
->canBeEnabled() | |||
->children() | |||
->scalarNode('fallback')->defaultValue('en')->end() | |||
->booleanNode('enable_logging')->defaultValue('%kernel.debug%')->end() |
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.
This doesn't work. Take a look at the documentation http://symfony.com/doc/current/cookbook/configuration/using_parameters_in_dic.html
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.
Also let's name it just logging
as in Swiftmailer/Doctrine other bundles.
👍 |
@@ -610,6 +610,8 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder | |||
} | |||
$translator->addMethodCall('setFallbackLocales', array($config['fallback'])); | |||
|
|||
$container->setParameter('translator.logging', $container->getParameterBag()->resolveValue($config['logging'])); |
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.
I don't see the point of resolving it here. Given that other places could overwrite the parameter anyway, this does not ensure it is resolved when reaching the compiler pass. The resolution should be moved to the compiler pass
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.
Why use non-usual way? Let's do on same manner like in Swiftmailer/Doctrine other bundles and how documentation suggests (provide argument $debug
for the configuration class.
👍 |
…e LoggableTranslatorPass.
…terface and TranslatorBagInterface.
b862638
to
c7ee300
Compare
Thank you @aitboudad. |
This PR was squashed before being merged into the 2.6-dev branch (closes #10887). Discussion ---------- [Translation] added LoggingTranslator. | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #3015, #2435 | License | MIT | Doc PR | symfony/symfony-docs/pull/4050 Commits ------- b7770bc [Translation] added LoggingTranslator.
return; | ||
} | ||
|
||
if ($container->getParameter('translator.logging')) { |
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.
This broke my symfony-master
ParameterNotFoundException in ParameterBag.php line 106: You have requested a non-existent parameter "translator.logging". Did you mean this: "translator.logging.class"?
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.
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.
I opened a PR: #12023
This addition is currently breaking my install: Catchable Fatal Error: Argument 1 passed to BM2\SiteBundle\Twig\GeographyExtension::__construct() must be an instance of Symfony\Component\Translation\Translator, instance of Symfony\Component\Translation\LoggingTranslator given, called in /home/maf/symfony/app/cache/test/appTestDebugProjectContainer.php on line 4885 and defined The funny part is that changing GeographyExtension leads to the inverse error - now it expects LoggingTranslator, but is given Translator. |
@tvogt Have you tryed typehint using |
Using the
should be
It seems like the default framework |
@rvanlaak any code typehinting the concrete implementation rather than the interface will suffers from issues as soon as a bundle extends the functionalities of service through composition (which is a much better way than doing it through inheritance). You should also rely on the interface for the typehint rather than on concrete implementations |
@stof I totally agree with you, but couldn't find something about it in the changelog @aitboudad +1 for enabling the logging by default, it is a great feature! |
->will($this->returnValue($parameterBag)); | ||
|
||
$pass = new LoggingTranslatorPass(); | ||
$pass->process($container); |
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.
The container is just a data container, why don't you just test if the data you expect to be added in the container is there rather than writing tests to see if the container gets called the way you think it gets called?
It will make the test easier to update and less fragile, as the inner workings may change over time while the input and output stay the same.
I just update to 2.6@dev. Note that the translator (service I got it from php app/console container:debug :
Edit: |
In both debug and non-debug? |
No, I got Symfony\Bundle\FrameworkBundle\Translation\Translator from |
@Koc yes, of course. |
…lator (derrabus) This PR was merged into the 2.6 branch. Discussion ---------- [Translation] [2.6] Upgrade information for LoggingTranslator | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | none When upgrading a Symfony 2.5 project to the 2.6 branch, I noticed that the `@translator` service was changed. In the affected project, we've had a service that depends on the `@translator` service and uses a type hint to ensure that a `Translator` instance is passed to the constructor. With the introduction of the `LoggingTranslator` class (PR #10887), this type hint now fails. I have added a small note to ` UPGRADE-2.6.md` in case more people stumble across this changed behavior. Commits ------- cd55a81 Upgrade information for the Translation component regarding the new LoggingTranslator class.
This PR was submitted for the master branch but it was merged into the 2.6 branch instead (closes #4050). Discussion ---------- [Translation] added logging capability. | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes(symfony/symfony/pull/10887) | Applies to | 2.6+ |Fixed tickets | - Commits ------- e8e50fa added logging to translator.