wp-cli / i18n-command

Provides internationalization tools for WordPress projects.
MIT License
96 stars 52 forks source link

`Call to undefined method WP_CLI\I18n\MakePotCommand::get_file_data_from_string()` (`wp i18n make-pot`) #336

Closed strarsis closed 2 years ago

strarsis commented 2 years ago

@swissspidy:

Describe the current, buggy behavior wp i18n make-pot . ./resources/lang/sage.pot --include="app,resources"

Theme stylesheet detected.
PHP Fatal error:  Uncaught Error: Call to undefined method WP_CLI\I18n\MakePotCommand::get_file_data_from_string() in phar:///usr/local/bin/wp/vendor/wp-cli/i18n-command/src/IterableCodeExtractor.php:58

Remember to provide some context to make sure we're all on the same page when reasoning about this.

Describe how other contributors can replicate this bug

  1. Ensure there is a directory that contains PHP files (files that just contain <?php with a php file extension are sufficient).
  2. Invoke this command so that directory is scanned: wp i18n make-pot . ./resources/lang/sage.pot --include=\"app,resources\" Note the fatal error:
    Theme stylesheet detected.
    PHP Fatal error:  Uncaught Error: Call to undefined method WP_CLI\I18n\MakePotCommand::get_file_data_from_string() in phar:///usr/local/bin/wp/vendor/wp-cli/i18n-command/src/IterableCodeExtractor.php:58

Describe what you would expect as the correct outcome No PHP fatal errors, a POT file is generated from the scanned source files.

Let us know what environment you are running this on

Error with PHP 8.1:

OS:     Linux 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64
Shell:  /bin/bash
PHP binary:     /usr/bin/php8.1
PHP version:    8.1.8
php.ini used:   /etc/php/8.1/cli/php.ini
MySQL binary:   /usr/bin/mysql
MySQL version:  mysql  Ver 8.0.30-0ubuntu0.20.04.2 for Linux on x86_64 ((Ubuntu))
SQL modes:
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       /home/build/src/example.com/site/web/app/themes/sage
WP-CLI packages dir:    /home/build/.wp-cli/packages/
WP-CLI global config:
WP-CLI project config:  /home/build/src/example.com/site/wp-cli.yml
WP-CLI version: 2.6.0

Same error with PHP 7.4:

OS:     Linux 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64
Shell:  /bin/bash
PHP binary:     /usr/bin/php7.4
PHP version:    7.4.30
php.ini used:   /etc/php/7.4/cli/php.ini
MySQL binary:   /usr/bin/mysql
MySQL version:  mysql  Ver 8.0.30-0ubuntu0.20.04.2 for Linux on x86_64 ((Ubuntu))
SQL modes:
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       /home/build/src/example.com/site/web/app/themes/example
WP-CLI packages dir:    /home/build/.wp-cli/packages/
WP-CLI global config:
WP-CLI project config:  /home/build/src/example.com/site/wp-cli.yml
WP-CLI version: 2.6.0

Provide a possible solution A similar issue points to a missing PHP extension, but this extension is installed for the used PHP versions (8.1; 7.4): https://github.com/wp-cli/i18n-command/issues/138 This issue occurs with wp i18n installed using wp package install wp-cli/i18n-command:dev-main. The issue doesn't occur when using wp i18n from cloned repository.

swissspidy commented 2 years ago

This issue occurs with wp i18n installed using wp package install wp-cli/i18n-command:dev-main.

It sounds like you're using an old version. Have you tried wp package update?

Alternatively, uninstall the package and update to WP-CLI nightly which has the latest version of the package.

strarsis commented 2 years ago

Have you tried wp package update?

Yes, wp package update did something, I ran it multiple times. But the issue persists.

Alternatively, uninstall the package and update to WP-CLI nightly which has the latest version of the package.

Yes, this fixed the issue. No package uninstallation was necessary by the way. I just ran wp cli update --nightly (as root/sudo) and after the successful update the same wp i18n make-pot command worked just fine.

strarsis commented 1 year ago

@swissspidy: It would be great if a new release could be published, so the fixes are also in the stable version.