From 70f72ff2a171d2a644e5a9652b794faaea63d19e Mon Sep 17 00:00:00 2001 From: Kamran Abdul Aziz Date: Mon, 19 Oct 2026 19:53:25 +0530 Subject: [PATCH] Menus: Use plural forms for the quick search result count. The menu item quick search announced its result count with `__( '%d Search Results Found' )`, which reads "1 Search Results Found" for a single result and gives translators no plural forms. Use `_n()` with a translators comment and the existing "%d result found." pair. Adds a QUnit test for the announced text. See #66341. --- src/js/_enqueues/lib/nav-menu.js | 9 ++++++++- tests/qunit/wp-admin/js/nav-menu.js | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/js/_enqueues/lib/nav-menu.js b/src/js/_enqueues/lib/nav-menu.js index 5e94a2b34f3c9..382fbad0acc52 100644 --- a/src/js/_enqueues/lib/nav-menu.js +++ b/src/js/_enqueues/lib/nav-menu.js @@ -1839,7 +1839,14 @@ }); $('.categorychecklist', panel).html( $items ); - wp.a11y.speak( wp.i18n.sprintf( wp.i18n.__( '%d Search Results Found' ), $items.length ), 'assertive' ); + wp.a11y.speak( + wp.i18n.sprintf( + /* translators: %d: Number of search results found. */ + wp.i18n._n( '%d result found.', '%d results found.', $items.length ), + $items.length + ), + 'assertive' + ); $( '.spinner', panel ).removeClass( 'is-active' ); wrapper.removeClass( 'has-no-menu-item' ); diff --git a/tests/qunit/wp-admin/js/nav-menu.js b/tests/qunit/wp-admin/js/nav-menu.js index c630d078297de..e6694d57e515e 100644 --- a/tests/qunit/wp-admin/js/nav-menu.js +++ b/tests/qunit/wp-admin/js/nav-menu.js @@ -92,5 +92,29 @@ } ); + QUnit.test( 'Quick search announces the number of results with the right plural form.', function( assert ) { + var spoken = [], + $wrapper = $( '

    ' ), + $panel = $wrapper.find( '.tabs-panel' ), + a11y, + speak; + + // Mock wp.a11y.speak() to record what is announced. + window.wp = window.wp || {}; + a11y = window.wp.a11y = window.wp.a11y || {}; + speak = a11y.speak; + a11y.speak = function( message ) { + spoken.push( message ); + }; + + try { + wpNavMenu.processQuickSearchQueryResponse( '
  • First
  • ', {}, $panel ); + wpNavMenu.processQuickSearchQueryResponse( '
  • First
  • Second
  • ', {}, $panel ); + } finally { + a11y.speak = speak; + } + + assert.deepEqual( spoken, [ '1 result found.', '2 results found.' ] ); + } ); } )( window.QUnit, jQuery );