Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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

Closed
wants to merge 1 commit into from
Closed

[Translation] Add TranslatorFallbackInterface, fixes #25356 #25549

wants to merge 1 commit into from

Conversation

Warxcell
Copy link
Contributor

@Warxcell Warxcell commented Dec 19, 2017

Q A
Branch? master
Bug fix? no
New feature? kind of
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #25356
License MIT
Doc PR no

@Simperfit
Copy link
Contributor

Could you please squash all the commits ? You should link the email you comitted with to your github account.

@Warxcell
Copy link
Contributor Author

@Simperfit done.

namespace Symfony\Component\Translation;

/**
* TranslatorFallbackInterface.
Copy link
Contributor

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.
Copy link
Contributor

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.

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 used description as-is from Translator.php

public function getFallbackLocales();

/**
* Sets the fallback locales.
Copy link
Contributor

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.

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 used description as-is from Translator.php

Copy link
Contributor

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.

Copy link
Contributor Author

@Warxcell Warxcell Dec 20, 2017

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.

Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

to be removed

Copy link
Contributor Author

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?

Copy link
Contributor

@Simperfit Simperfit Dec 20, 2017

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
Copy link
Contributor

Choose a reason for hiding this comment

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

to be removed

@Simperfit
Copy link
Contributor

Since it's a new feature could you please target master ?

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');
Copy link
Contributor

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');
Copy link
Contributor

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
Copy link
Contributor Author

@Simperfit I'm not sure if it's whole new feature, because the code still looks and acts like before.
The same reason I think tests are enough. I could only assert all fallback tests that Translator is fallback translator ?

@Simperfit
Copy link
Contributor

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 master but I may be wrong. @xabbuh WDYT ?

@Warxcell
Copy link
Contributor Author

@Simperfit I added some tests. You can see them.

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Dec 20, 2017
Copy link
Member

@nicolas-grekas nicolas-grekas left a 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);
Copy link
Member

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
Copy link
Contributor Author

Removed redundant descriptions and typehints.

Replace assertTrue with assertInstanceOf

@stof
Copy link
Member

stof commented Dec 20, 2017

this must indeed go in master

@Warxcell Warxcell changed the base branch from 2.7 to master December 20, 2017 10:36
*
* @throws \InvalidArgumentException If a locale contains invalid characters
*/
public function setFallbackLocales(array $locales);
Copy link
Member

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.

Copy link
Contributor Author

@Warxcell Warxcell Dec 20, 2017

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.

Copy link
Member

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
Copy link
Contributor Author

Rebased from master.

@xabbuh xabbuh modified the milestones: 2.7, 4.1 Dec 20, 2017
src/Symfony/Component/Translation/LoggingTranslator.php Outdated Show resolved Hide resolved
@Warxcell
Copy link
Contributor Author

@xabbuh I made the requested changes. I just don't get what's the problem with appveyor?

@Warxcell
Copy link
Contributor Author

Warxcell commented Dec 21, 2017

Actually I still believe that setFallbackLocales should be in API, as it's used by framework bundle.

https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L888

What will happens if translator is replaced in some project with translator that does not support fallback locales?

@xabbuh
Copy link
Member

xabbuh commented Dec 22, 2017

The failure on AppVeyor is not related to these changes.

@Warxcell
Copy link
Contributor Author

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 nicolas-grekas modified the milestones: 4.1, next Apr 20, 2018
@nicolas-grekas
Copy link
Member

I think I'm 👎 here: getFallbackLocales only fits reflection purposes in the code base. We'd better deprecate it actually and find another way for data collectors and debug:translation. Let's reduce the complexity instead of increasing it.

@Warxcell
Copy link
Contributor Author

Warxcell commented Sep 21, 2018

@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
Copy link
Member

Setting the same options/locales/fallbacks when configuring your translator seems the best option to me.

@nicolas-grekas
Copy link
Member

Closing in favor of #28579

@nicolas-grekas nicolas-grekas modified the milestones: next, 4.2 Nov 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.