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

I18n: Fix broken loop in WP_Theme_JSON_Resolver #33624

Merged
merged 1 commit into from
Jul 22, 2021

Conversation

gziolo
Copy link
Member

@gziolo gziolo commented Jul 22, 2021

Description

Fixes #33552.

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;
 }

This PR applies the changes proposed by @schlessera.

How has this been tested?

npm run test-php

Types of changes

Bug fix (non-breaking change which fixes an issue).

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@gziolo gziolo self-assigned this Jul 22, 2021
@gziolo gziolo requested a review from schlessera July 22, 2021 09:30
@gziolo gziolo added Internationalization (i18n) Issues or PRs related to internationalization efforts [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 22, 2021
@gziolo gziolo requested a review from jorgefilipecosta July 22, 2021 09:52
@gziolo gziolo merged commit 803604f into trunk Jul 22, 2021
@gziolo gziolo deleted the fix/broken-loop-wp-theme-json-resolver branch July 22, 2021 10:03
@github-actions github-actions bot added this to the Gutenberg 11.2 milestone Jul 22, 2021
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 [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken loop in WP_Theme_JSON_Resolver
2 participants