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] added extract messages from controllers #26738

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 7 commits into from
Closed

[Translation] added extract messages from controllers #26738

wants to merge 7 commits into from

Conversation

thomasage
Copy link

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
License MIT

Added a loop on controllers to extract messages.

@@ -127,6 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($this->defaultViewsPath) {
$viewsPaths[] = $this->defaultViewsPath;
}
$controllersPaths = array($kernel->getRootDir().'/Controller');
Copy link
Contributor

Choose a reason for hiding this comment

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

What if my controllers are somewhere else?

Copy link
Author

Choose a reason for hiding this comment

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

@iltar you're right. I added a parameter to constructor (as for the views). But I'm not sure how to test it. Can you help me?

Copy link
Contributor

Choose a reason for hiding this comment

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

What about making the parameter an array of paths? That would cover multiple locations. You can test it by writing fixtures for your test, writing controllers with translations.

Copy link
Author

Choose a reason for hiding this comment

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

An array of paths sounds great to me, but for the tests I wonder how to set path(s) when I call the command on CLI (bin/console translation:update)?

When I try your suggestion, it returns null for $this->router.
I'm not sure it's OK to have a behaviour for templates (parameter in constructor) and another behaviour for controllers (find auto).

Copy link
Contributor

@linaori linaori left a comment

Choose a reason for hiding this comment

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

There's a small issue with the current implementation:

  • It assumes a certain directory
  • I can only add 1 extra directory

It's hard to find all controllers (but not impossible).

In a command, you could do something like this:

public function execute(InputInterface $input, OutputInterface $output)
{
    $rows = [];

    foreach ($this->router->getRouteCollection() as $route) {
        if (!$route->hasDefault('_controller')) {
            continue;
        }

        $request = new Request([], [], ['_controller' => $route->getDefault('_controller')]);
        $controller = $this->resolver->getController($request);
    }
}

The other option would be to pass a list of resolved controllers or a list of directories (less accurate).

@linaori
Copy link
Contributor

linaori commented Apr 3, 2018

You'll have to inject the router RouterInterface (router service) for it to work.

@thomasage
Copy link
Author

Do you think it's a good option to have 2 different behaviours for templates and controllers?

@thomasage
Copy link
Author

If I inject RouterInterface, I will break BC (constructor signature will require a new parameter).

@linaori
Copy link
Contributor

linaori commented Apr 9, 2018

You can make it optional, or not typehint it and resolve the actual type (+deprecation warning) in the constructor

@thomasage
Copy link
Author

I injected RouterInterface and scan for controllers.

@fabpot fabpot modified the milestones: 4.1, next Apr 22, 2018
@nicolas-grekas
Copy link
Member

Instead of hardcoding something for controllers only, what about allowing to configure a list of paths in a "translation.something" configuration option and make the command look there? That would work for controllers but also for anything else, wdyt?

Another idea could be to detect all services that have the translator injected into them and consider them all as targets for translation extraction.

@thomasage
Copy link
Author

Instead of hardcoding something for controllers only, what about allowing to configure a list of paths in a "translation.something" configuration option and make the command look there? That would work for controllers but also for anything else, wdyt?

Another idea could be to detect all services that have the translator injected into them and consider them all as targets for translation extraction.

I prefer your 2nd idea, but I've no clue how do that. I don't think that "grep" every PHP classes is a right way?

@yceruto
Copy link
Member

yceruto commented Nov 8, 2018

See #29121 for alternative solution implementing the 2nd idea.

@thomasage thomasage closed this Nov 20, 2018
@thomasage
Copy link
Author

Closed in favor of #29121.

@stof stof removed this from the next milestone Nov 23, 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.

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