$blueprint_groups Preview's own `blueprints` list (in display order). * @param array $skipped_counts Skip reason => count (e.g. `['conflict' => 1]`); a zero/absent reason is omitted. * @return string */ public static function preview( string $generator, array $blueprint_groups, array $skipped_counts ): string { $label = Generators::label( $generator ); $total = 0; $group_parts = array(); foreach ( $blueprint_groups as $group ) { $count = (int) ( $group['product_count'] ?? 0 ); $total += $count; /* translators: 1: template name (saved or built-in), 2: product count for that Blueprint. */ $group_parts[] = sprintf( __( '%1$s (%2$d)', 'ai-product-tools' ), (string) ( $group['name'] ?? '' ), $count ); } if ( empty( $group_parts ) ) { $sentence = sprintf( /* translators: 1: generator label (e.g. "Product title"), 2: product count. */ _n( 'Will write %1$s for %2$d product.', 'Will write %1$s for %2$d products.', $total, 'ai-product-tools' ), $label, $total ); } else { $sentence = sprintf( /* translators: 1: generator label, 2: product count, 3: comma-separated "template name (count)" list. */ _n( 'Will write %1$s for %2$d product: %3$s.', 'Will write %1$s for %2$d products: %3$s.', $total, 'ai-product-tools' ), $label, $total, implode( ', ', $group_parts ) ); } $skip_parts = array(); foreach ( $skipped_counts as $reason => $count ) { $count = (int) $count; if ( $count > 0 ) { $skip_parts[] = self::skipPhrase( (string) $reason, $count ); } } if ( ! empty( $skip_parts ) ) { /* translators: %s: comma-separated list such as "2 products not found, 1 product you cannot edit". */ $sentence .= ' ' . sprintf( __( 'Skipped: %s.', 'ai-product-tools' ), implode( ', ', $skip_parts ) ); } $sentence .= ' ' . __( 'Nothing has been written yet.', 'ai-product-tools' ); return $sentence; } /** * A readable phrase for one skip reason; the response's `skipped` list * keeps the machine-readable code. * * @param string $reason Skip reason code: not_found, forbidden or conflict. * @param int $count Number of products skipped for this reason. * @return string */ private static function skipPhrase( string $reason, int $count ): string { switch ( $reason ) { case 'not_found': /* translators: %d: number of products. */ return sprintf( _n( '%d product not found', '%d products not found', $count, 'ai-product-tools' ), $count ); case 'forbidden': /* translators: %d: number of products. */ return sprintf( _n( '%d product you cannot edit', '%d products you cannot edit', $count, 'ai-product-tools' ), $count ); case 'conflict': /* translators: %d: number of products. */ return sprintf( _n( '%d product with a template conflict', '%d products with a template conflict', $count, 'ai-product-tools' ), $count ); default: /* translators: 1: number of products, 2: skip reason code. */ return sprintf( __( '%1$d (%2$s)', 'ai-product-tools' ), $count, $reason ); } } }