Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails

WCEmailTemplateChangeSummary::to_summary_linesprivate staticWC 1.0

Render the structured payload into pre-localized one-liners, using a fixed string catalog. The "N of M" position-and-total disambiguator (e.g. "Updated wording in Paragraph 1 of 2") only fires when a block label appears more than once on the matched side.

Method of the class: WCEmailTemplateChangeSummary{}

No Hooks.

Returns

String[].

Usage

$result = WCEmailTemplateChangeSummary::to_summary_lines( $structured ): array;
$structured(array) (required)
.

WCEmailTemplateChangeSummary::to_summary_lines() code WC 10.9.1

private static function to_summary_lines( array $structured ): array {
	$lines = array();

	// Singular form drops the indefinite article ("Added Image block" rather
	// than "Added a Image block") because English a/an depends on phonetics
	// the catalog can't infer at format time, and many target locales have no
	// equivalent article at all. Plural already reads "Added 3 Image blocks"
	// without an article, so dropping it in singular keeps both forms
	// stylistically consistent.
	$added_labels = array_map( static fn( array $e ): string => (string) ( $e['label'] ?? '' ), $structured['added_blocks'] );
	$added_counts = array_count_values( array_filter( $added_labels, static fn( string $l ): bool => '' !== $l ) );
	foreach ( $added_counts as $label => $count ) {
		$count = (int) $count;
		if ( 1 === $count ) {
			$lines[] = sprintf(
				/* translators: %s: block name */
				__( 'Added %s block', 'woocommerce' ),
				(string) $label
			);
		} else {
			$lines[] = sprintf(
				/* translators: 1: number of blocks added; 2: block name */
				__( 'Added %1$d %2$s blocks', 'woocommerce' ),
				$count,
				(string) $label
			);
		}
	}

	$removed_labels = array_map( static fn( array $e ): string => (string) ( $e['label'] ?? '' ), $structured['removed_blocks'] );
	$removed_counts = array_count_values( array_filter( $removed_labels, static fn( string $l ): bool => '' !== $l ) );
	foreach ( $removed_counts as $label => $count ) {
		$count = (int) $count;
		if ( 1 === $count ) {
			$lines[] = sprintf(
				/* translators: %s: block name */
				__( 'Removed %s block', 'woocommerce' ),
				(string) $label
			);
		} else {
			$lines[] = sprintf(
				/* translators: 1: number of blocks removed; 2: block name */
				__( 'Removed %1$d %2$s blocks', 'woocommerce' ),
				$count,
				(string) $label
			);
		}
	}

	foreach ( $structured['copy_changes'] as $change ) {
		$label      = (string) ( $change['block'] ?? '' );
		$occurrence = (int) ( $change['occurrence'] ?? 1 );
		$total      = (int) ( $change['total'] ?? 1 );

		if ( $total > 1 ) {
			$lines[] = sprintf(
				/* translators: 1: block name (e.g. "Paragraph"); 2: position of the edited block (e.g. 1); 3: total blocks of that type in the template (e.g. 2). Reads as "Updated wording in Paragraph 1 of 2". */
				__( 'Updated wording in %1$s %2$d of %3$d', 'woocommerce' ),
				$label,
				$occurrence,
				$total
			);
		} else {
			$lines[] = sprintf(
				/* translators: %s: block name */
				__( 'Updated wording in %s', 'woocommerce' ),
				$label
			);
		}
	}//end foreach

	foreach ( $structured['structural_changes'] as $change ) {
		$desc = (string) ( $change['description'] ?? '' );
		if ( '' !== $desc ) {
			$lines[] = $desc;
		}
	}

	return $lines;
}