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

Support Blade Templates #147

Closed
dac514 opened this issue Mar 13, 2019 · 5 comments
Closed

Support Blade Templates #147

dac514 opened this issue Mar 13, 2019 · 5 comments

Comments

@dac514
Copy link
Contributor

dac514 commented Mar 13, 2019

Currently, this CLI command supports PHP and two types of JavaScript extraction. Eventually, the code that does this leads back to / depends on: Gettext\Extractors\PhpCode and Gettext\Utils\JsFunctionsScanner

oscarotero/Gettext supports several other extractors, one of them is Blade templates.

Our WordPress project uses Blade templates. The naming convention for Blade templates is: /path/to/name.blade.php The strings inside those files looks like: {{ __( 'My English string', 'my-plugin-name' ) }} The i18n-command finds, scans, and fails to extract anything meaningful from those files.

Please support Blade templates. I'm willing to write a PR to do this if this issue isn't closed as a #wontfix.

Related: #52

@swissspidy
Copy link
Member

How are you currently extracting strings from your files? Do you perhaps have a link to your project?

The original goal was to make it easy to extract strings in a similar fashion to the old makepot script, which is only concernced with "regular" PHP files, and to add support for the new JS features.

@dac514
Copy link
Contributor Author

dac514 commented Mar 13, 2019

Hi @swissspidy

How are you currently extracting strings from your files? Do you perhaps have a link to your project?

The project is Pressbooks:
https://github.com/pressbooks/pressbooks/tree/dev/languages

We use wp-cli to generate the .pot source files. Note: We run your branch for plurals. We do:

wp i18n make-pot . languages/<plugin>.pot --exclude="vendor,symbionts" --headers='{"Report-Msgid-Bugs-To":"https://github.com/pressbooks/<plugin>/"}'

We then send the generated files to Transifex:
https://github.com/pressbooks/pressbooks/blob/dev/bin/i18n.sh

Here's a hack at getting it working with Blade templates. I don't think it's a good idea.
pressbooks/pressbooks#1616

The original goal was to make it easy to extract strings in a similar fashion to the old makepot script, which is only concernced with "regular" PHP files, and to add support for the new JS features.

Yes, I understand this, (after the fact). I'm at the point where either either Blade templates (could) work with wp i18n or i'm going to convert them to plain php files and pull the plug on Blade in our project.

Thanks!

@schlessera
Copy link
Member

We're still trying to work out how best to extend bundled commands like wp i18n. Ideally, I think you should be able to provide a separate third-party package that extends the wp i18n command to be able to support Blade templates.

To actually make this work, I think the best approach would be to just pull in the BladeCompiler class, compile into regular PHP and then provide it to the regular parser.

@dac514
Copy link
Contributor Author

dac514 commented Mar 22, 2019

Thanks for the tip @schlessera. I overrode WP_CLI\I18n\MakePotCommand and got it working in our project.

Commit is here: pressbooks/pb-cli@afe5bb1

Closing bug.

@swissspidy
Copy link
Member

There is now this PR for supporting Blade template extraction: #304

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

3 participants