wp-cli / i18n-command

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

Missing file name and line numbers in POT file #352

Closed maikeoldsea closed 1 year ago

maikeoldsea commented 1 year ago

Bug Report

Describe the current, buggy behavior When generating a .POT file, the file does not contain the source file name or line number for the extracted string. I see:

msgid "Hello world"
msgstr ""

I was expecting something like:

#: test.php:1
msgid "Hello world"
msgstr ""

Older versions of WP-CLI (2.4.x) seem to be able to parse the file correctly.

Describe how other contributors can replicate this bug

  1. Download the WP-CLI .phar file and create 'wp.bat' as described in the installation instructions (https://make.wordpress.org/cli/handbook/guides/installing/)

  2. Create a test PHP file:

<?php
$x = __('Hello world');
?>
  1. From a command prompt, issue this command to create the .POT file: wp i18n make-pot . test.pot --ignore-domain

Check the contents of the resulting 'test.pot' file. I see:

msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2023-02-07T04:29:05+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.7.1\n"

msgid "Hello world"
msgstr ""

Let us know what environment you are running this on Windows, WP-CLI installed as .phar, PHP 7.4.0

(Paste the output of "wp cli info" into this box)
OS:     Windows NT 10.0 build 22621 (Windows 10) AMD64
Shell:  C:\WINDOWS\system32\cmd.exe
PHP binary:     C:\wamp64\bin\php\php7.4.0\php.exe
PHP version:    7.4.0
php.ini used:   C:\wamp64\bin\php\php7.4.0\php.ini
MySQL binary:
MySQL version:
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:       C:\test
WP-CLI packages dir:    C:\Users\havem/.wp-cli/packages/
WP-CLI cache dir:       C:\Users\havem/.wp-cli/cache
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.7.1
swissspidy commented 1 year ago

Hmm that might be a Windows issue, because we definitely do extract file name & line numbers and all our tests verify that. Unfortunately I don‘t have a Windows machine to test.

Does it work with WSL?

maikeoldsea commented 1 year ago

I haven't tried WSL since I'm using windows

On Mon, Feb 6, 2023, 23:45 Pascal Birchler @.***> wrote:

Hmm that might be a Windows issue, because we definitely do extract file name & line numbers and all our tests verify that. Unfortunately I don‘t have a Windows machine to test.

Does it work with WSL?

— Reply to this email directly, view it on GitHub https://github.com/wp-cli/i18n-command/issues/352#issuecomment-1420332099, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5XAJRH4QAY3NKXIKNBDBW3WWH4SPANCNFSM6AAAAAAUTPHIIE . You are receiving this because you are subscribed to this thread.Message ID: @.***>

maikeoldsea commented 1 year ago

Any luck finding a Windows machine to confirm this issue on yet? I'm stuck without make-pot. It's such a basic example it seems like it must affect other (Windows) users as well.

swissspidy commented 1 year ago

I‘d recommend installing WSL on your machine and then installing WP-CLI there

maikeoldsea commented 1 year ago

I can't use WSL in a Windows build process, but regardless, it seems like it'd make more sense for you to install a Windows partition and just fix the bug(s).

pedro-mendonca commented 1 year ago

Hi, just tested on Windows setup: PHP 7.4.32 WP-CLI 2.7.1

PHP file:

<?php
$x = __('Hello world');
?>

POT output: Success: POT file successfully generated!

msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2023-02-16T08:58:33+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.7.1\n"

#: test.php:2
msgid "Hello world"
msgstr ""

wp cli --info:

OS:     Windows NT 10.0 build 19044 (Windows 10) AMD64
Shell:  C:\WINDOWS\system32\cmd.exe
PHP binary:     ******\php.exe
PHP version:    7.4.32
php.ini used:   ******
MySQL binary:
MySQL version:
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:       ******
WP-CLI packages dir:
WP-CLI cache dir:       ******
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.7.1
pbiron commented 1 year ago

WFM, I get the same results as @pedro-mendonca :

PHP file:

<?php
$x = __('Hello world');
?>

Command

wp i18n make-pot . test.pot --ignore-domain

Output

msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2023-02-16T07:57:23-07:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.7.1\n"

#: test.php:2
msgid "Hello world"
msgstr ""

wp --info

OS:     Windows NT 10.0 build 22621 (Windows 10) AMD64
Shell:  C:\WINDOWS\system32\cmd.exe
PHP binary:     <path>\7.4.29\php.exe
PHP version:    7.4.29
php.ini used:   <path>\7.4.29\php.ini
MySQL binary:
MySQL version:
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:       <path>\wp-content\plugins\test-make-pot
WP-CLI packages dir:    <path>/.wp-cli/packages/
WP-CLI cache dir:       <path>/.wp-cli/cache
WP-CLI global config:   <path>/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 2.7.1
swissspidy commented 1 year ago

Closing this for now since this can't be reproduced yet.

If it can be reproduced reliably, I am happy to reopen it.