-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translation] Add TranslatorFallbackInterface, fixes #25356 #25549
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
Could you please squash all the commits ? You should link the email you comitted with to your github account. |
@Simperfit done. |
namespace Symfony\Component\Translation; | ||
|
||
/** | ||
* TranslatorFallbackInterface. |
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 is not needed
interface TranslatorFallbackInterface extends TranslatorInterface | ||
{ | ||
/** | ||
* Gets the fallback locales. |
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 method name is self explanatory.
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 used description as-is from Translator.php
public function getFallbackLocales(); | ||
|
||
/** | ||
* Sets the fallback locales. |
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 method name is self explanatory.
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 used description as-is from Translator.php
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.
You can remove this IMHO.
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.
Everywhere else there is a description. This method is also self-explanatory, but it has description.
/**
* Returns the current locale.
*
* @return string The locale
*/
public function getLocale();
I think it should stay.
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 understand the point but the fact is this should be cleaned : #24931
@@ -18,7 +18,14 @@ | ||
*/ | ||
class IdentityTranslator implements TranslatorInterface | ||
{ | ||
/** | ||
* @var MessageSelector |
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.
to be removed
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? I think it's good to typehint variables in docblock?
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 does not add anything because we already know this with the constructor.
private $selector; | ||
|
||
/** | ||
* @var string |
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.
to be removed
Since it's a new feature could you please target Also you are missing some test ;) |
public function setFallbackLocales(array $locales) | ||
{ | ||
if (!$this->translator instanceof TranslatorFallbackInterface) { | ||
throw new \BadMethodCallException('The original translator does not support fallback locales'); |
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.
missing dot at te end
public function setFallbackLocales(array $locales) | ||
{ | ||
if (!$this->translator instanceof TranslatorFallbackInterface) { | ||
throw new \BadMethodCallException('The original translator does not support fallback locales'); |
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.
missing dot at the end
@Simperfit I'm not sure if it's whole new feature, because the code still looks and acts like before. |
For the test you need to assert that an exception is thrown when the translator does not implement the new interface. IMHO it's a new interface, it should be in |
@Simperfit I added some tests. You can see them. |
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.
adding a new interface is definitely a new feature to me, so this should be for master, isn't it?
@@ -134,6 +136,7 @@ public function testSetFallbackLocalesMultiple() | ||
// force catalogue loading | ||
$translator->trans('bar'); | ||
|
||
$this->assertTrue($translator instanceof TranslatorFallbackInterface); |
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.
you should use assertInstanceOf everywhere
Removed redundant descriptions and typehints. Replace |
this must indeed go in master |
* | ||
* @throws \InvalidArgumentException If a locale contains invalid characters | ||
*/ | ||
public function setFallbackLocales(array $locales); |
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'm not sure this method needs to be in the interface. Configuring the instance does not need to belong in the API.
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.
Then why TranslatorInterface
has ability to setLocale
?
I'm just following the same pattern. Indeed I agree that if the Translation Component
does not need to configure Translator
, it should be only inside implementation.
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 locale can change throughout the request. But I agree with @stof that this is probably not needed for the fallback locales.
Rebased from master. |
@xabbuh I made the requested changes. I just don't get what's the problem with appveyor? |
Actually I still believe that What will happens if translator is replaced in some project with translator that does not support fallback locales? |
The failure on AppVeyor is not related to these changes. |
Let's say I also want to build something like "listener". A callback - when locale/fallback locales is/are changed inside translator - something to happen? |
I think I'm 👎 here: |
@nicolas-grekas actually I'm not using that for debug purposes. I have built Entity Translation Bundle (for translating objects, mainly entities) which can be coupled with Symfony Translator (share same locale and fallback locales) instead of setting twice same thing. Is there way to acomplish that with data collector? |
Setting the same options/locales/fallbacks when configuring your translator seems the best option to me. |
Closing in favor of #28579 |
Uh oh!
There was an error while loading. Please reload this page.