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

Strings from WordPress core's block-library.js are not extracted #255

Closed
2 tasks done
ocean90 opened this issue Jul 5, 2021 · 7 comments
Closed
2 tasks done

Strings from WordPress core's block-library.js are not extracted #255

ocean90 opened this issue Jul 5, 2021 · 7 comments

Comments

@ocean90
Copy link
Contributor

ocean90 commented Jul 5, 2021

Bug Report

Describe the current, buggy behavior

First reported on Slack here. The translation project for WordPress 5.8 is missing some strings, particularly from block-library.js.

Describe how other contributors can replicate this bug

  • Download block-library.js
  • Create a new folder with block-library.js
  • cd into the new folder
  • run wp i18n make-pot . --ignore-domain (or php -d memory_limit=1G $(which wp) i18n make-pot . --ignore-domain in case of memory limit issues)
  • Open block-library.pot and notice that no strings are extracted

Describe what you would expect as the correct outcome

The resulting POT file should include "Text settings", "Toggle to show a large initial letter.", "Drop cap" any many more.

Let us know what environment you are running this on

❯ wp cli info
OS:	Darwin 20.5.0 Darwin Kernel Version 20.5.0: Sat May  8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 x86_64
Shell:	/bin/zsh
PHP binary:	/usr/local/Cellar/[email protected]/7.4.19_1/bin/php
PHP version:	7.4.19
php.ini used:	/usr/local/etc/php/7.4/php.ini
MySQL binary:	/usr/local/bin/mysql
MySQL version:	mysql  Ver 15.1 Distrib 10.3.28-MariaDB, for osx10.16 (x86_64) using readline 5.1
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:	/Users/Dominik/Desktop/block-library
WP-CLI packages dir:	/Users/Dominik/.wp-cli/packages/
WP-CLI global config:	/Users/Dominik/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version:	2.5.0

Provide additional context/Screenshots

Might be related to WordPress now using modern JavaScript syntax for these files.

@swissspidy
Copy link
Member

If you use the —debug flag, is there any warning about the file not being parseable?

@ocean90
Copy link
Contributor Author

ocean90 commented Jul 5, 2021

Yep!

Debug (make-pot): Parsing file block-library.js (0.103s)
Debug (make-pot): Could not parse file block-library.js: Unexpected: ( (line 28847, column 5) (2.469s)
Debug (make-pot): Extracted 0 strings (2.53s)
const getTermsInfo = terms => ({
  terms,
  ...(terms === null || terms === void 0 ? void 0 : terms.reduce((accumulator, term) => { // This is line 28847
    const {
      mapById,
      mapByName,
      names
    } = accumulator;
    mapById[term.id] = term;
    mapByName[term.name] = term;
    names.push(term.name);
    return accumulator;
  }, {
    mapById: {},
    mapByName: {},
    names: []
  }))
});

@swissspidy
Copy link
Member

Just did a quick test in Peast and it seems that the issue seems to be related to the parentheses around the object expression.

Oddly enough the following code seems to work:

const getTermsInfo = terms => {
    return {
        terms,
        ...(terms === null || terms === void 0 ? void 0 : terms.reduce((accumulator, term) => { // This is line 28847
            const {
            mapById,
            mapByName,
            names
            } = accumulator;
            mapById[term.id] = term;
            mapByName[term.name] = term;
            names.push(term.name);
            return accumulator;
        }, {
            mapById: {},
            mapByName: {},
            names: []
        }))
    };
}

I filed a bug upstream: mck89/peast#38

@gziolo
Copy link
Contributor

gziolo commented Jul 6, 2021

As a quick fix can we split this very complex expression in smaller chunks, for example:

const getTermsInfo = terms => {
    const rest = terms === null || ....;
    return {
        terms,
        ...rest
    };
}

@swissspidy
Copy link
Member

@ocean90 With the underlying bug now fixed, you could update the Peast dependency in your fork of this package that you're using on dotorg.

I assume we'll update the dependency here once there's a new tagged release.

@ocean90
Copy link
Contributor Author

ocean90 commented Jul 13, 2021

@ocean90 With the underlying bug now fixed, you could update the Peast dependency in your fork of this package that you're using on dotorg.

This was done in ocean90/wp-cli-bundle@47e8927 and deployed to dotorg. The updated POT file does now include the missing block-library strings, see https://i18n.trac.wordpress.org/changeset/623359.

@swissspidy
Copy link
Member

Awesome, closing this one for now then 👍

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