diff --git a/mu-plugins/blocks/query-filter/render.php b/mu-plugins/blocks/query-filter/render.php index 08711b53d..00ca93dd2 100644 --- a/mu-plugins/blocks/query-filter/render.php +++ b/mu-plugins/blocks/query-filter/render.php @@ -58,8 +58,25 @@ ); if ( $selected_count && $has_multiple ) { - /* translators: %s is count of currently selected filters. */ - $apply_label = sprintf( __( 'Apply (%s)', 'wporg' ), $selected_count ); + $special_singular_mappings = array( + 'categories' => 'category', + ); + + // Possible Input: 'popular tags 1' + // Expected Output: 'popular tags' + $label = strtolower( preg_replace( '/\s\d+$/', '', strip_tags( $settings['label'] ) ) ); + $label_form = 1 === $selected_count + ? ( isset( $special_singular_mappings[ $label ] ) + ? $special_singular_mappings[ $label ] + : substr( $label, 0, -1 ) ) + : $label; + + $apply_label = sprintf( + /* translators: 1: the count of currently selected filters. 2: taxonomy being filtered */ + __( 'Apply %1$s %2$s', 'wporg' ), + $selected_count, + $label_form + ); } else { $apply_label = __( 'Apply', 'wporg' ); } diff --git a/mu-plugins/blocks/query-filter/src/view.js b/mu-plugins/blocks/query-filter/src/view.js index c56881e41..03a2b2231 100644 --- a/mu-plugins/blocks/query-filter/src/view.js +++ b/mu-plugins/blocks/query-filter/src/view.js @@ -25,6 +25,15 @@ function closeDropdown( store ) { document.documentElement.classList.remove( 'is-query-filter-open' ); } +function getTaxonomyForm( count, pluralTaxonomy ) { + const specialSingularMappings = { + categories: 'category', + }; + return count === 1 + ? specialSingularMappings[ pluralTaxonomy ] || pluralTaxonomy.slice( 0, -1 ) + : pluralTaxonomy; +} + function updateButtons( store, count ) { const { context } = store; if ( ! context.wporg.queryFilter.form ) { @@ -33,12 +42,17 @@ function updateButtons( store, count ) { const applyButton = context.wporg.queryFilter.form.querySelector( 'input[type="submit"]' ); const clearButton = context.wporg.queryFilter.form.querySelector( '.wporg-query-filter__modal-action-clear' ); + const taxonomy = context.wporg.queryFilter.toggleButton.textContent.replace( /\s\d+$/, '' ).toLowerCase(); // Only update the apply button if multiple selections are allowed. if ( context.wporg.queryFilter.hasMultiple ) { if ( count ) { - /* translators: %s is count of currently selected filters. */ - applyButton.value = sprintf( __( 'Apply (%s)', 'wporg' ), count ); + applyButton.value = sprintf( + /* translators: 1: the count of currently selected filters. 2: taxonomy being filtered */ + __( 'Apply %1$s %2$s', 'wporg' ), + count, + getTaxonomyForm( count, taxonomy ) + ); } else { applyButton.value = __( 'Apply', 'wporg' ); }