I’m developing a child theme and I want to get .pot file using wp-cli.
I follow the wp-cli handbook and run:
cd /media/sf_TOOLS/ubuntu-20.04/bin curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
then in the folder where are theme files I run:
/media/sf_TOOLS/ubuntu-20.04/bin/wp-cli.phar i18n make-pot --domain=test-child . languages/test-child.pot
This command generate a .pot file without theme strings:
msgid "" msgstr "" "Project-Id-Version: n" "Report-Msgid-Bugs-To: n" "Last-Translator: FULL NAME <<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="26636b676f6a6667626274637575">[email protected]</a>>n" "Language-Team: LANGUAGE <<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="632f2f230f0a4d0c1104">[email protected]</a>>n" "MIME-Version: 1.0n" "Content-Type: text/plain; charset=UTF-8n" "Content-Transfer-Encoding: 8bitn" "POT-Creation-Date: 2020-12-29T09:38:20+01:00n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONEn" "X-Generator: WP-CLI 2.4.0n" "X-Domain: test-childn"
so using --debug option I got this log:
Debug (bootstrap): No readable global config found (1.419s) Debug (bootstrap): No project config found (1.419s) Debug (bootstrap): argv: /media/sf_TOOLS/ubuntu-20.04/bin/wp-cli.phar i18n make-pot --debug --domain=test-child . languages/test-child.pot (1.419s) Debug (bootstrap): ABSPATH defined: / (1.447s) Debug (hooks): Processing hook "before_run_command" with 1 callbacks (1.463s) Debug (hooks): On hook "before_run_command": WP_CLIBootstrapRegisterDeferredCommands->add_deferred_commands() (1.463s) Debug (bootstrap): Running command: i18n make-pot (1.463s) Debug (make-pot): No valid theme stylesheet or plugin file found, treating as a regular project. (1.603s) Debug (make-pot): Extracting all strings with text domain "test-child" (1.604s) Debug (make-pot): Destination: languages/test-child.pot (1.604s) Debug (make-pot): Excluding the following files: node_modules,.git,.svn,.CVS,.hg,vendor,Gruntfile.js,webpack.config.js,*.min.js (2.047s) Debug (make-pot): Extracted 0 strings (2.151s)
It seems that: No valid theme stylesheet or plugin file found.
In the folder where I run wp-cli there is a file style.css that contains:
/* Theme Name: Test Child Theme URI: https://www.example.com/ Author: Test Author Author URI: https://www.example.com/ Description: Child Theme just for test. Tags: translation-ready, custom-background, theme-options, custom-menu, threaded-comments, featured-images, footer-widgets, editor-style, right-sidebar, full-width-template, two-columns, grid-layout, custom-colors, custom-header, custom-logo, featured-image-header, portfolio, news, entertainment Version: 1.0.8 Requires at least: 5.0 Tested up to: 5.4.1 Requires PHP: 5.6 License: Test License License URI: https://www.example.com/test_license.html Text Domain: test-child Template: test */
Theme file that contains strings to be translated is in admin sub-folder, here is an example of string that I expect to see in .pot file:
<button type="button" class="button rnc-user-image_remove <?php if ( empty($userImage) ) { echo 'hidden'; } ?>"><?php _e('Remove this image', 'test-child'); ?></button>
I’ve also tested in my wordpress development site running command in:
wp-content/themes/test-child
but I got the same result.
What is wrong here?
Here is wp-cli --info result:
$ /media/sf_TOOLS/ubuntu-20.04/bin/wp-cli.phar --info OS: Linux 5.4.0-58-generic #64-Ubuntu SMP Wed Dec 9 08:16:25 UTC 2020 x86_64 Shell: /bin/bash PHP binary: /usr/bin/php7.4 PHP version: 7.4.3 php.ini used: /etc/php/7.4/cli/php.ini 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: /media/sf_TEST/test-child WP-CLI packages dir: WP-CLI global config: WP-CLI project config: WP-CLI version: 2.4.0
I got the same result running the command on a theme downloaded from official repository.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The problem here is that WordPress project folder is a shared folder on Ubuntu VirtualBox guest OS with guest additions.
Searching in wp cli source code, I found that to scan the directory is used:
$files = new IteratorIterator( new DirectoryIterator( $this->source ) );
and I could verify that it returns only . and .. files.
Moving WordPress project files, for example, in $HOME directory and it works as expected.
make-pot needs mbstring package, so I have to install it with:
sudo apt-get install php-mbstring
I don’t know if it is a php bug or a Ubuntu bug, but on local filesystem it works.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0