Skip to content
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

[Translation] translation:extract with bundle - should also extract translations from PHP code #54798

Open
cuchac opened this issue May 2, 2024 · 1 comment

Comments

@cuchac
Copy link
Contributor

cuchac commented May 2, 2024

Symfony version(s) affected

7.1

Description

Documentation mentions

The translation:extract command looks for missing translations in:
...
 - Any PHP file/class that injects or autowires the translator service and makes calls to the trans() method..
...

When bundle is specified, this does not work as stated. Following line limits path to extract texts to only bundle template folder:

$codePaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates'];

I did not find any other official way to extract PHP code translations from bundle. I believe at least PHP files using translator service should be included in extracted bundle translations.

How to reproduce

php bin/console translation:extract --force fr AcmeBundle

Only translations from templates (AcmeBundle/templates) are extracted. No PHP trans() calls are extracted.

Possible Solution

Use result from $this->getRootCodePaths($kernel) and leave all files from given bundle.

$codePaths = $this->getRootCodePaths($kernel);
$currentName = 'default directory';
// Override with provided Bundle info
if (null !== $input->getArgument('bundle')) {
try {
$foundBundle = $kernel->getBundle($input->getArgument('bundle'));
$bundleDir = $foundBundle->getPath();
$transPaths = [is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundleDir.'/translations'];
$codePaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates'];

Additional Context

No response

@cuchac
Copy link
Contributor Author

cuchac commented May 2, 2024

Would you accept contribution to handle this issue? Should there be any command-line parameter or it could be the default behavior?

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

2 participants