-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add support for PHP-Blade files #304
Conversation
Refactor the IterableCodeExtractor filter so it supports multiple file extensions (`blade.php`).
…ile extensions. Deduplicate file extension check.
features/makepot.feature
Outdated
@endsection | ||
""" | ||
|
||
When I try `wp i18n make-pot example-project result.pot --ignore-domain --debug` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An additional scenario for testing extraction without --ignore-domain
would be helpful too.
Thanks for opening this! For context, Blade support was originally proposed in #147 but was more seen as out of scope. But this might be a reasonable addition after all. |
…sn't apply to PHP-blade templates.
@swissspidy: After adding a test that doesn't ignore the translation domains, I noticed an issue with the PHP function scanner. It probably needs some adjustments. 🐱 |
What kind of issue?
|
…(3.52 for PHP 7.0 support).
@swissspidy: The PHP The tests pass fine except for the one that doesn't ignore the translation domains, it doesn't include any translations from the blade file then. I still try to figure out what the reason is, probably the PHP function scanner. |
Fix scenario (with translation domains).
@swissspidy: Alright, the translation domain issue was fixed. I would really like to see this merged (and released) so I can easily use it, |
Add unit tests for IterableCodeExtractor::file_has_file_extension.
@schlessera WDYT about the PHP version requirement bump mentioned above (and this enhancement in general)? |
@swissspidy, @strarsis The current PHP version requirement policy is the following: |
@schlessera: So even PHP 7.1 would be still too high for The good news is that the Blade Engine It would be great if this PR can be merged, I need |
This command already has a higher PHP version requirement AFAIK |
@swissspidy: Great that this was merged! I can install this WP CLI command from source, but it would be even better if it is published as a new release. Are there plans for a new release of |
We should be able to tag a new release soon, but usually that's done closer to the release of WP-CLI itself. In the meantime, |
Edit: Available with recent release of |
This PR adds the code and (simple) tests for extracting translations strings from PHP-Blade template files.
Luckily the
4.x
branch of thegettext
project already contains a fully working PHP-Blade Extractor,which can be used very similarly to the PHP extractor for
wp i18n
.The
IterableCodeExtractor
file filter had to be refactored a bit to make it also support filtering for multiple file extensions (as it is the case withblade.php
for PHP-Blade template files).The
illuminate/view
BladeOne
compiler for a standalone PHP-Blade compiler had to be included ascomposer
dependency as thegettext
package doesn't require it on its own/expects a PHP-Blade compiler to be available. Edit: Because of current PHP version constraints byi18n
, a release of another, standalone and well-maintained PHP-Blade compiler is used instead (BladeOne
).Discussion
Both classes,
PhpCodeExtractor
andBladeCodeExtractor
duplicate some code,$options
and$functionsScannerClass
:https://github.com/strarsis/i18n-command/blob/add-blade-extractor/src/PhpCodeExtractor.php#L13-L46
https://github.com/strarsis/i18n-command/blob/add-blade-extractor/src/BladeCodeExtractor.php#L13-L46
Side note: Putting these two aforementioned fields
$options
and$functionsScannerClass
into a PHPtrait
doesn't work as PHPtrait
s can't override class fields (as I learned by trying to do so).Both classes have to extend from a class from
gettext/gettext
, therefore a trivial way for letting both classes share these fields doesn't seem to exist, so I think those duplications (which are quite compact) can be tolerated.