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

Broken loop in WP_Theme_JSON_Resolver #33552

Closed
schlessera opened this issue Jul 19, 2021 · 3 comments · Fixed by #33624
Closed

Broken loop in WP_Theme_JSON_Resolver #33552

schlessera opened this issue Jul 19, 2021 · 3 comments · Fixed by #33624
Assignees
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. Internationalization (i18n) Issues or PRs related to internationalization efforts [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@schlessera
Copy link
Member

schlessera commented Jul 19, 2021

The loop in WP_Theme_JSON_Resolver to extract translatable paths is broken, as it contains an immediate and unconditional return. This causes the loop to immediately exit again after the first iteration, thus never actually looping.

foreach ( $partial_child as $key => $context ) {
return array(
array(
'path' => $current_path,
'key' => $key,
'context' => $context,
),
);
}

This means that the extraction only works where there's only a single item in the array of translatable strings per section (i.e. the 'name' field).

The suggested code would be:

	foreach ( $partial_child as $key => $context ) { 
		$result[] = array(
			'path'    => $current_path, 
			'key'     => $key, 
			'context' => $context, 
		);
	);
	return $result;
 }
@schlessera schlessera added [Type] Bug An existing feature does not function as intended [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. labels Jul 19, 2021
@swissspidy swissspidy added the Internationalization (i18n) Issues or PRs related to internationalization efforts label Jul 19, 2021
@swissspidy
Copy link
Member

cc @gziolo @nosolosw

@gziolo
Copy link
Member

gziolo commented Jul 19, 2021

Yes, good catch. It’s an obvious bug from #28246 that I didn’t catch only because we had only one field used for all translatable paths 😅
We need a test that uses a custom schema and requires several fields to be translated, a good example would be in the i18n schema for block.json:

"variations": [
{
"title": "block variation title",
"description": "block variation description",
"keywords": [ "block variation keyword" ]
}
]

At some point, we could also unify the logic that applies translations based on i18n schemas.
I recently proposed https://github.com/WordPress/wordpress-develop/blob/92a8fda178379f7366054f26580ae756da0dcbda/src/wp-includes/blocks.php#L219-L247 that could work for both, but it doesn’t cover the case with * that theme.json has.

@gziolo gziolo self-assigned this Jul 22, 2021
@gziolo gziolo added the [Status] In Progress Tracking issues with work in progress label Jul 22, 2021
pento pushed a commit to WordPress/wordpress-develop that referenced this issue Jul 22, 2021
Related issue in Gutenberg: WordPress/gutenberg#33552

The loop in WP_Theme_JSON_Resolver to extract translatable paths was broken, as it contained an immediate and unconditional return. This caused the loop to immediately exit again after the first iteration, thus never actually looping.

Follow-up to [50959].

Props schlessera.
 


git-svn-id: https://develop.svn.wordpress.org/trunk@51472 602fd350-edb4-49c9-b593-d223f7449a82
nylen pushed a commit to nylen/wordpress-develop-svn that referenced this issue Jul 22, 2021
Related issue in Gutenberg: WordPress/gutenberg#33552

The loop in WP_Theme_JSON_Resolver to extract translatable paths was broken, as it contained an immediate and unconditional return. This caused the loop to immediately exit again after the first iteration, thus never actually looping.

Follow-up to [50959].

Props schlessera.
 


git-svn-id: https://develop.svn.wordpress.org/trunk@51472 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this issue Jul 22, 2021
Related issue in Gutenberg: WordPress/gutenberg#33552

The loop in WP_Theme_JSON_Resolver to extract translatable paths was broken, as it contained an immediate and unconditional return. This caused the loop to immediately exit again after the first iteration, thus never actually looping.

Follow-up to [50959].

Props schlessera.
 

Built from https://develop.svn.wordpress.org/trunk@51472


git-svn-id: http://core.svn.wordpress.org/trunk@51083 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@gziolo
Copy link
Member

gziolo commented Jul 22, 2021

It was also backported to WordPress core: WordPress/wordpress-develop@3f83b50.

gMagicScott pushed a commit to gMagicScott/core.wordpress-mirror that referenced this issue Jul 22, 2021
Related issue in Gutenberg: WordPress/gutenberg#33552

The loop in WP_Theme_JSON_Resolver to extract translatable paths was broken, as it contained an immediate and unconditional return. This caused the loop to immediately exit again after the first iteration, thus never actually looping.

Follow-up to [50959].

Props schlessera.
 

Built from https://develop.svn.wordpress.org/trunk@51472


git-svn-id: https://core.svn.wordpress.org/trunk@51083 1a063a9b-81f0-0310-95a4-ce76da25c4cd
pento pushed a commit to WordPress/wordpress-develop that referenced this issue Jul 30, 2021
Related issue in Gutenberg: WordPress/gutenberg#33552.

The loop in `WP_Theme_JSON_Resolver` to extract translatable paths was broken, as it contained an immediate and unconditional return. This caused the loop to immediately exit again after the first iteration, thus never actually looping.

Follow-up to [50959].

Props schlessera.
Merges [51472] to the 5.8 branch.
Fixes #53738.

git-svn-id: https://develop.svn.wordpress.org/branches/5.8@51515 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this issue Jul 30, 2021
Related issue in Gutenberg: WordPress/gutenberg#33552.

The loop in `WP_Theme_JSON_Resolver` to extract translatable paths was broken, as it contained an immediate and unconditional return. This caused the loop to immediately exit again after the first iteration, thus never actually looping.

Follow-up to [50959].

Props schlessera.
Merges [51472] to the 5.8 branch.
Fixes #53738.
Built from https://develop.svn.wordpress.org/branches/5.8@51515


git-svn-id: http://core.svn.wordpress.org/branches/5.8@51126 1a063a9b-81f0-0310-95a4-ce76da25c4cd
gMagicScott pushed a commit to gMagicScott/core.wordpress-mirror that referenced this issue Jul 30, 2021
Related issue in Gutenberg: WordPress/gutenberg#33552.

The loop in `WP_Theme_JSON_Resolver` to extract translatable paths was broken, as it contained an immediate and unconditional return. This caused the loop to immediately exit again after the first iteration, thus never actually looping.

Follow-up to [50959].

Props schlessera.
Merges [51472] to the 5.8 branch.
Fixes #53738.
Built from https://develop.svn.wordpress.org/branches/5.8@51515


git-svn-id: https://core.svn.wordpress.org/branches/5.8@51126 1a063a9b-81f0-0310-95a4-ce76da25c4cd
F-Wilke pushed a commit to FiliagoDev/WordPress that referenced this issue Jul 31, 2021
Related issue in Gutenberg: WordPress/gutenberg#33552.

The loop in `WP_Theme_JSON_Resolver` to extract translatable paths was broken, as it contained an immediate and unconditional return. This caused the loop to immediately exit again after the first iteration, thus never actually looping.

Follow-up to [50959].

Props schlessera.
Merges [51472] to the 5.8 branch.
Fixes #53738.
Built from https://develop.svn.wordpress.org/branches/5.8@51515


git-svn-id: http://core.svn.wordpress.org/branches/5.8@51126 1a063a9b-81f0-0310-95a4-ce76da25c4cd
whereiscodedude pushed a commit to whereiscodedude/wpss that referenced this issue Sep 18, 2022
Related issue in Gutenberg: WordPress/gutenberg#33552.

The loop in `WP_Theme_JSON_Resolver` to extract translatable paths was broken, as it contained an immediate and unconditional return. This caused the loop to immediately exit again after the first iteration, thus never actually looping.

Follow-up to [50959].

Props schlessera.
Merges [51472] to the 5.8 branch.
Fixes #53738.
Built from https://develop.svn.wordpress.org/branches/5.8@51515
VenusPR added a commit to VenusPR/Wordpress_Richard that referenced this issue Mar 9, 2023
Related issue in Gutenberg: WordPress/gutenberg#33552.

The loop in `WP_Theme_JSON_Resolver` to extract translatable paths was broken, as it contained an immediate and unconditional return. This caused the loop to immediately exit again after the first iteration, thus never actually looping.

Follow-up to [50959].

Props schlessera.
Merges [51472] to the 5.8 branch.
Fixes #53738.
Built from https://develop.svn.wordpress.org/branches/5.8@51515


git-svn-id: http://core.svn.wordpress.org/branches/5.8@51126 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. Internationalization (i18n) Issues or PRs related to internationalization efforts [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants