Skip to content

Broken loop in WP_Theme_JSON_Resolver #33552

Closed

Description

@schlessera

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

Activity

  1. added
    [Type] BugAn existing feature does not function as intended
    [Feature] ThemesQuestions or issues with incorporating or styling blocks in a theme.
    on Jul 19, 2021
  2. swissspidy commented on Jul 19, 2021

    @swissspidy
    Member
  3. gziolo commented on Jul 19, 2021

    @gziolo
    Member

    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.

  4. self-assigned this
    on Jul 22, 2021
  5. gziolo commented on Jul 22, 2021

    @gziolo
    Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Internationalization (i18n)Issues or PRs related to internationalization efforts[Feature] ThemesQuestions or issues with incorporating or styling blocks in a theme.[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions