Skip to content

Overwrite 'i18n extract' to make it able to parse twig templates too. - #121

Open
Antronin wants to merge 10 commits into
cakephp:2.xfrom
Antronin:TwigI18nExtract
Open

Antronin wants to merge 10 commits into
cakephp:2.xfrom
Antronin:TwigI18nExtract

Conversation

@Antronin

Copy link
Copy Markdown

This is an enchantment for Twig-View, for issue #91.
With these changes, users can still use i18n extract, but it can now parse Twig files and collect all translations from them in the same way the original command does for PHP files.

@Antronin
Antronin marked this pull request as draft August 18, 2026 13:17
@Antronin

Copy link
Copy Markdown
Author

Can somebody help me with explaining:

  1. What went wrong in the CI 8.2 lowest job? Why it is not finding an instance method which was found in all other jobs?
  2. How to complete phpstan's requirements? CakePhp IO contains the Progress helper, why Phpstan cannot find it?

@Antronin
Antronin marked this pull request as ready for review August 19, 2026 11:32
@web-dev-passion

Copy link
Copy Markdown

Can somebody help me with explaining:

  1. What went wrong in the CI 8.2 lowest job? Why it is not finding an instance method which was found in all other jobs?
  2. How to complete phpstan's requirements? CakePhp IO contains the Progress helper, why Phpstan cannot find it?

I think the 2 phpstan issues are connected to each other.

  1. Wants use statements instead of FQDN -> you added use correctly (https://github.com/cakephp/twig-view/pull/121/changes#diff-59ba34bcfd866a3c81304fe024d9412e0b5ca0ae7bf60862edd8ef06fc24fe95R23)
  2. Wants to use the Progress instead of FQDN -> you forgot removing the FQDN (https://github.com/cakephp/twig-view/pull/121/changes#diff-59ba34bcfd866a3c81304fe024d9412e0b5ca0ae7bf60862edd8ef06fc24fe95R64)

@Antronin

Copy link
Copy Markdown
Author

Thanks, but that's not the error. In PHPUnit, I receive this error, but ONLY in CI:

1) Cake\TwigView\Test\TestCase\Command\I18nExtractCommandTest::testExecute
assert($progress instanceof ProgressHelper)

/home/runner/work/twig-view/twig-view/src/Command/TwigExtractCommand.php:64

I'm not sure why the assert is a problem, even though the same PHP version (8.2.33) runs successfully in another CI task.

And for the Coding Standard check, the error is this:

Fatal error: Uncaught Rector\Exception\Reflection\MissingPrivatePropertyException: Property "$container" was not found in "PHPStan\Parser\RichParser" class in /home/runner/work/twig-view/twig-view/vendor/rector/rector/src/Util/Reflection/PrivatesAccessor.php:82

That is not even my code, but Rector's.

@markstory markstory added the enhancement New feature or request label Sep 13, 2026
@markstory

Copy link
Copy Markdown
Member

I wouldn't worry too much about the rector failure. We probably need to update dependencies there.

Comment thread src/Command/TwigExtractCommand.php Resolved
Comment thread src/Command/TwigExtractCommand.php Resolved
Comment thread src/Command/TwigExtractCommand.php Resolved
/**
* Language string extractor
*/
class TwigExtractCommand extends I18nExtractCommand

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Extending the core command class could make this brittle in the future. We don't provide any backward compatibility promises on protected APIs (which you're using quite a bit here).

What if we had a separate command that only processed twig files, and left the core i18n extract command alone?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I would not do it. When you have Twig in your project, you can still have PHP files containing translatable strings. So this must be an enhancement to the I18nExtractCommand, not a separate solution.
And using two separate commands (one for Twig and one for all PHP files) will not work, because the second one running won't know about the first's findings.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Maybe the solution is to update I18nExtractCommand to support additional parsers for different file types; what I did is a step in that direction.

@ADmad ADmad Sep 15, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, ideally the core I18nExtractCommand needs to be made flexible so that it can be configured to use custom parses and storage types.

My use case is that I want to store the message in the database instead of the pot files. I too have extended and overwritten parts of core's I18nExtract to achieve that which isn't very nice https://github.com/ADmad/cakephp-i18n/blob/master/src/Command/I18nExtractCommand.php

@krugerman007

Copy link
Copy Markdown

Hey guys, have you got any updates? We would use this feature too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants