8000 Unused state of some translations which are really used · Issue #29085 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Unused state of some translations which are really used #29085

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
BonBonSlick opened this issue Nov 4, 2018 · 7 comments
Closed

Unused state of some translations which are really used #29085

BonBonSlick opened this issue Nov 4, 2018 · 7 comments

Comments

@BonBonSlick
Copy link
BonBonSlick commented Nov 4, 2018

I am not sure if it is expected behaviour.
According to docs https://symfony.com/doc/current/translation/debug.html
I run command php bin/console debug:translation nl --domain=messages --only-unused
and got all unused translations, but, some of them used!
Example

 State         Domain                     Id         Message Preview (nl)        Fallback Message Preview (en)          
  unused  |  messages  |  xml.searchTitle.days.total  | voor %total% ...  |   xml.searchTitle.days.total                
 ---------- ---------- ------------------------------------------------------------------- ---------------------------------------
php bin/console debug:translation nl --domain=messages --only-unused

But with global search I found that this translation is used

 if ($totalDays <= 3) {
                $params['%days%'] = $this->translator->trans(
                    'xml.searchTitle.days.specific',
                    [
                        '%days%' => $this->availabilitiesToString($availabilitySchedule, true),
                    ]
                );
            } else {
                $params['%days%'] = $this->translator->trans('xml.searchTitle.days.total', ['%total%' => $totalDays]);
            }

Why is shows state unused when it is used?

There area thousands of translations, because this command is not reliable I cant trust it, I have to check every translation manually if it is used...
There are a lot of cases with wrong state.
Strange but I found above unused states, that translations with unused state I removed, now has state missing, if I return them, they have both states, used and unused at the same time.
It happens not with all translations, some of them really unused, missing or used and has only one state.
Also, I am not sure if translations which used in twig counted, because found many with status used, but they are used in twig templates.
And some message when adding flash in controller is also missed, state unused.

@xabbuh
Copy link
Member
xabbuh commented Nov 5, 2018

Unfortunately, that's expected. As the docs state the command is only able to find translation usages in templates.

@BonBonSlick
Copy link
Author

Thank you @xabbuh So everyone also search translations with global IDE search ?

@nicolas-grekas
Copy link
Member

Until now yes. In theory it could be possible to extract more messages by analyzing the code, but someone would need to contribute the code :)

@nicolas-grekas
Copy link
Member

Hum actually there is already a PhpExtractor and #26738 on the topic. Maybe we should allow configuring the paths where the command should look for translations?

@yceruto
Copy link
Member
yceruto commented Nov 6, 2018

The translator config already has a paths option that can be used for other translation dirs and they are not supported by commands yet, so yes, we're missing some messages here.

I can try it.

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

Sounds interesting... I'll take a look.

@BonBonSlick
Copy link
Author
BonBonSlick commented Nov 7, 2018

Thank you for your response.

@fabpot fabpot closed this as completed Feb 13, 2019
fabpot added a commit that referenced this issue Feb 13, 2019
…tor paths, Twig paths and Translator aware services paths in commands (yceruto)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[FrameworkBundle][Translation] Add support for Translator paths, Twig paths and Translator aware services paths in commands

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29085, #29633, #17739
| License       | MIT
| Doc PR        | TODO

Add custom (also common) Twig and Translation paths to the translation commands:
 * Custom directories configured in `twig.paths`.
 * Custom directories configured in `translator.paths`
 * The `Resources/translations/` directory of `Validation` component (if installed).
 * The `Resources/translations/` directory of `Form` component (if installed).
 * The `Resources/translations/` directory of Security Core component (if installed).

Commits
-------

31d7a09 Add support for translator paths and twig paths in translation commands
@yceruto
Copy link
Member
yceruto commented Feb 13, 2019

I did not move the issue reference after splitting the PR so it should probably remain open waiting for #30120

@xabbuh xabbuh reopened this Feb 13, 2019
@fabpot fabpot closed this as completed Feb 16, 2019
fabpot added a commit that referenced this issue Feb 16, 2019
…iles with trans() in translation commands (yceruto)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[FrameworkBundle][Translation] Added support for PHP files with trans() in translation commands

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29085
| License       | MIT
| Doc PR        | -

This PR allows translation commands be able to debug and update translation messages from any PHP file/class defined as service, injecting or wiring the `translator` service, e.g.:
```php
use Symfony\Component\Translation\TranslatorInterface;

class ParallelUniverseController extends AbstractController
{
    public function hello(Request $request, TranslatorInterface $translator)
    {
        // this id 'hello_message' will be extracted from translation:update
        $message = $translator->trans('hello_message');

        // send message to space...
    }
}
```
this supports all ways of wiring (auto or not): via constructor, public property, method calls, service subscriber and controller argument.

Commits
-------

9f9b828 Added support for PHP files with translation in translation commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0