Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Simperfit commentedDec 20, 2017
Could you please squash all the commits ? You should link the email you comitted with to your github account. |
Warxcell commentedDec 20, 2017
@Simperfit done. |
| namespaceSymfony\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 TranslatorFallbackInterfaceextends 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
| publicfunctiongetFallbackLocales(); | ||
| /** | ||
| * 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 */publicfunctiongetLocale();
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
| class IdentityTranslatorimplements 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?
SimperfitDec 20, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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
Simperfit commentedDec 20, 2017
Since it's a new feature could you please target Also you are missing some test ;) |
| publicfunctionsetFallbackLocales(array$locales) | ||
| { | ||
| if (!$this->translatorinstanceof TranslatorFallbackInterface) { | ||
| thrownew \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
| publicfunctionsetFallbackLocales(array$locales) | ||
| { | ||
| if (!$this->translatorinstanceof TranslatorFallbackInterface) { | ||
| thrownew \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
Warxcell commentedDec 20, 2017
@Simperfit I'm not sure if it's whole new feature, because the code still looks and acts like before. |
Simperfit commentedDec 20, 2017
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 |
Warxcell commentedDec 20, 2017
@Simperfit I added some tests. You can see them. |
nicolas-grekas left a comment
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?
| // force catalogue loading | ||
| $translator->trans('bar'); | ||
| $this->assertTrue($translatorinstanceof 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
Warxcell commentedDec 20, 2017
Removed redundant descriptions and typehints. Replace |
stof commentedDec 20, 2017
this must indeed go in master |
| * | ||
| * @throws \InvalidArgumentException If a locale contains invalid characters | ||
| */ | ||
| publicfunctionsetFallbackLocales(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 whyTranslatorInterface has ability tosetLocale ?
I'm just following the same pattern. Indeed I agree that if theTranslation Component does not need to configureTranslator, 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.
Warxcell commentedDec 20, 2017
Rebased from master. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Warxcell commentedDec 21, 2017
@xabbuh I made the requested changes. I just don't get what's the problem with appveyor? |
Warxcell commentedDec 21, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Actually I still believe that What will happens if translator is replaced in some project with translator that does not support fallback locales? |
xabbuh commentedDec 22, 2017
The failure on AppVeyor is not related to these changes. |
Warxcell commentedDec 25, 2017
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? |
nicolas-grekas commentedSep 21, 2018
I think I'm 👎 here: |
Warxcell commentedSep 21, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@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? |
nicolas-grekas commentedSep 21, 2018
Setting the same options/locales/fallbacks when configuring your translator seems the best option to me. |
nicolas-grekas commentedSep 24, 2018
Closing in favor of#28579 |
Uh oh!
There was an error while loading.Please reload this page.