Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed as not planned
@cuchac

Description

@cuchac

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions