wp-cli / i18n-command

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

An issue in Pot generation with my minified js file #323

Closed iranimij closed 2 years ago

iranimij commented 2 years ago

sellkit.zip I attached the js file. It seems that there is a conflict between wp i18n make-pot and recharts, Because after adding recharts package it does not extract all js string. after removing the package it extracts all js strings. (PHP strings generation is ok).

https://recharts.org/en-US/ => "recharts": "^2.1.5", React => "react": "^16.13.1",

iranimij commented 2 years ago

@swissspidy Could you please check this issue?

swissspidy commented 2 years ago

Please acknowledge my "On vacation" status. Pings are not helpful for that :-)

Your JS file is very large. Do you perhaps have a smaller JS file that can be used to reproduce this?

What version of WP-CLI & i18n-command & PHP are you using?

Are there any errors?

Filling out the bug issue template would be helpful.

swissspidy commented 2 years ago

In a quick test the following strings were extracted from your JS file:

#: sellkit.js:237
msgid "Logo"
msgstr ""

#: sellkit.js:237
msgid "Docs"
msgstr ""

#: sellkit.js:237
msgid "Sellkit requires"
msgstr ""

#: sellkit.js:237
msgid "to be installed and activated to offer the Funnels feature."
msgstr ""

#: sellkit.js:237
msgid "Add New"
msgstr ""

#: sellkit.js:237
msgid "Back"
msgstr ""

#: sellkit.js:237
msgid "Date"
msgstr ""

#: sellkit.js:237
msgid "Loading..."
msgstr ""

#: sellkit.js:237
msgid "Last 7 days"
msgstr ""

#: sellkit.js:237
msgid "Last 30 days"
msgstr ""

#: sellkit.js:237
msgid "Visits"
msgstr ""

#: sellkit.js:237
msgid "Unique visits"
msgstr ""

#: sellkit.js:237
msgid "Bounce Rate"
msgstr ""

#: sellkit.js:237
msgid "Revenue"
msgstr ""

#: sellkit.js:237
msgid "Orders"
msgstr ""

#: sellkit.js:237
msgid "Conversion Rate"
msgstr ""

#: sellkit.js:237
msgid "Average Order Value"
msgstr ""

#: sellkit.js:237
msgid "Upsell Revenue"
msgstr ""

#: sellkit.js:237
msgid "Created Coupons"
msgstr ""

#: sellkit.js:237
msgid "Used Coupons"
msgstr ""

#: sellkit.js:237
msgid "Customers"
msgstr ""

#: sellkit.js:237
msgid "Total Discounts"
msgstr ""

#: sellkit.js:237
msgid "Impression"
msgstr ""

#: sellkit.js:237
msgid "Click"
msgstr ""

#: sellkit.js:237
msgid "Applied Discount"
msgstr ""

#: sellkit.js:237
msgid "Converted"
msgstr ""

#: sellkit.js:237
msgid "Welcome to SellKit! 👋"
msgstr ""

#: sellkit.js:237
msgid "Date Range"
msgstr ""

#: sellkit.js:237
msgid "Funnel Engagement"
msgstr ""

#: sellkit.js:237
msgid "Funnel Sales"
msgstr ""

#: sellkit.js:237
msgid "Smart Coupons"
msgstr ""

#: sellkit.js:237
msgid "Dynamic Discounts"
msgstr ""

#: sellkit.js:237
msgid "Smart Notices"
msgstr ""

#: sellkit.js:251
msgid "Submit"
msgstr ""

#: sellkit.js:251
msgid "Discard"
msgstr ""

#: sellkit.js:251
msgid "OK"
msgstr ""

#: sellkit.js:251
msgid "Settings"
msgstr ""

#: sellkit.js:251
msgid "Empty Cart Template"
msgstr ""

#: sellkit.js:251
msgid "Type to search"
msgstr ""

#: sellkit.js:251
msgid "This template will replace the default WooCommerce empty cart page content."
msgstr ""

#: sellkit.js:251
msgid "Skip Cart Page"
msgstr ""

#: sellkit.js:251
msgid "If enabled, the cart page will be disabled and customer will be redirected to the checkout page. it reduces the steps for faster conversion, therefore reducing abandoned carts."
msgstr ""

#: sellkit.js:251
msgid "Disallow search engine from indexing flows"
msgstr ""

#: sellkit.js:251
msgid "Facebook Pixel"
msgstr ""

#: sellkit.js:251
msgid "Facebook pixel ID"
msgstr ""

#: sellkit.js:251
msgid "Facebook Pixel Events"
msgstr ""

#: sellkit.js:251
msgid "Initiate Checkout"
msgstr ""

#: sellkit.js:251
msgid "Add Payment Info"
msgstr ""

#: sellkit.js:251
msgid "Purchase Complete"
msgstr ""

#: sellkit.js:251
msgid "Google Analytics"
msgstr ""

#: sellkit.js:251
msgid "Google Analytics ID"
msgstr ""

#: sellkit.js:251
msgid "Google Analytics Events"
msgstr ""

#: sellkit.js:251
msgid "Begin Checkout"
msgstr ""

#: sellkit.js:251
msgid "Add To Cart"
msgstr ""

#: sellkit.js:251
msgid "Purchase"
msgstr ""

#: sellkit.js:251
msgid "Google API Key"
msgstr ""

#: sellkit.js:251
msgid "Google API key is used by Checkout form Address Autocomplete feature. Obtain your API key through "
msgstr ""

#: sellkit.js:251
msgid "Google Cloud Platform Console."
msgstr ""

#: sellkit.js:251
msgid "Delete plugin data on plugin deletion"
msgstr ""

#: sellkit.js:251
msgid "Are you sure?"
msgstr ""

#: sellkit.js:251
msgid "Confirm"
msgstr ""

#: sellkit.js:251
msgid "Cancel"
msgstr ""

#: sellkit.js:251
msgid "Do you want to delete plugin data while deleting the plugin? Type \"DELETE\" to confirm!"
msgstr ""

#: sellkit.js:251
msgid "Type DELETE"
msgstr ""

#: sellkit.js:251
msgid "If you wish to altogether remove Sellkit data from your site (options, database, tables, etc), enable this option and save settings. On plugin deletion, the sellkit data also gets deleted permanently."
msgstr ""

#: sellkit.js:251
msgid "Save Settings"
msgstr ""

#: sellkit.js:251
msgid "Dashboard"
msgstr ""

#: sellkit.js:251
msgid "Funnels"
msgstr ""

Now which ones are missing here that you were expecting to be present?

iranimij commented 2 years ago

@swissspidy Sorry to interrupt you, I'm using WP-CLI 2.5.0 and PHP Version 8.0.8, this js file does not return any string for me.

There is a warning,

PHP Warning: Invalid argument supplied for foreach() in phar://C:/wp-cli/wp-cli.phar/vendor/wp-cli/i18n-command/src/MakePotCommand.php on line 853

Warning: Invalid argument supplied for foreach() in phar://C:/wp-cli/wp-cli.phar/vendor/wp-cli/i18n-command/src/MakePotCommand.php on line 853

but it does return strings for PHP files with these warnings, I think the issue is not related to these warnings.

swissspidy commented 2 years ago

I'm using WP-CLI 2.5.0

You should update to the latest version, WP-CLI 2.6.0

You can also just update this command like so: wp package install git@github.com:wp-cli/i18n-command.git

this js file does not return any string for me.

What exactly is the command you are using? What text domain are you expecting? Have you tried the --debug and --ignore-domain flags?

There is a warning,

This PHP warning is related to theme.json files and should not affect JS string extraction.

It is already fixed in the current development version of this command.

iranimij commented 2 years ago

@swissspidy I have used this command : wp i18n make-pot . --allow-root --domain=sellkit --skip-audit --exclude="build,docs,src,node_modules,vendor" --headers='{"Last-Translator":"Artbees Team info@artbees.net","Language-Team":"Artbees Team info@artbees.net"}' --file-comment="Copyright (c) $(date +'%Y') SellKit." languages/sellkit.pot

After using --debug mode : https://prnt.sc/jRGPmUIxRdjR I got this error : Debug (make-pot): Could not parse file release/assets/dist/admin/sellkit.js: Unexpected: 05 (line 21, column 7958) (1.879s)

Text-domain : 'sellkit' Btw, I ignored text-domain the issue still exists.

iranimij commented 2 years ago

@swissspidy BTW, After updating wp-cli and the command, I'm getting this error : https://prnt.sc/pLzs5iiqkTP0 Allowed memory size of 536870912 bytes exhausted (tried to allocate 20971520 bytes) in phar://C:/wp-cli/wp-cli.phar/vendor/mck89/peast/lib/Peast/Syntax/CommentsRegistry.php on line 170

swissspidy commented 2 years ago

See https://make.wordpress.org/cli/handbook/guides/common-issues/ for increasing the memory limit.

iranimij commented 2 years ago

@swissspidy Could you please check that error again, the error is a little weird, Allowed memory size is much more than 20971520

swissspidy commented 2 years ago

The error message can be a bit misleading. Please check https://make.wordpress.org/cli/handbook/guides/common-issues/ for increasing the memory limit regardless.

iranimij commented 2 years ago

@swissspidy I increased it to memory_limit=1024M but the issue still persists, Do you think it's normal?

iranimij commented 2 years ago

I also tested 2048M memoty_limit, I think there is an infinite loop, that makes this issue. Could you please tell me what memory limit did you use that you could extract the strings from my js file?

swissspidy commented 2 years ago

I used php -d memory_limit=512M "$(which wp)" i18n make-pot foo-theme --ignore-domain where foo-theme is a folder with a style.css file and your JS file in it.

If you suspect an infinite loop problem, I recommend coming up with a small reproducible test case and opening an issue at https://github.com/mck89/peast

iranimij commented 2 years ago

Could you please remove that memory_limit command and test it again?

swissspidy commented 2 years ago

Without it I get "Allowed memory size ... exhausted" errors, which is kinda expected since it's a super big JS file that takes a lot of memory to parse.

iranimij commented 2 years ago

Uh My God, sorry to disturb you, I have had two Xamp on my local and It seems that my wp-cli is installed on another PHP. I was checking with another PHP. after checking that, the issue was fixed.

For someone who may have the same issue, There were two issues, 1_My packages were not updated. wp-cli and the command. 2_My PHP limit memory was not enough for the Js file, the js file was so big.

@swissspidy Thank you very much.