diff --git src/wp-admin/js/customize-widgets.js src/wp-admin/js/customize-widgets.js index d3a4edcc64..b482e8d607 100644 --- src/wp-admin/js/customize-widgets.js +++ src/wp-admin/js/customize-widgets.js @@ -1616,7 +1616,7 @@ * @returns {void} */ updateNotice = function() { - var activeSectionCount = getActiveSectionCount(), message, nonRenderedAreaCount, registeredAreaCount; + var activeSectionCount = getActiveSectionCount(), someRenderedMessage, nonRenderedAreaCount, registeredAreaCount; noticeContainer.empty(); registeredAreaCount = api.Widgets.data.registeredSidebars.length; @@ -1624,15 +1624,17 @@ if ( 0 !== activeSectionCount ) { nonRenderedAreaCount = registeredAreaCount - activeSectionCount; - message = ( 1 === nonRenderedAreaCount ? l10n.someAreasShown.singular : l10n.someAreasShown.plural ).replace( '%d', nonRenderedAreaCount ); + someRenderedMessage = l10n.someAreasShown[ nonRenderedAreaCount ]; } else { - message = ( 1 === registeredAreaCount ? l10n.noAreasShown.singular : l10n.noAreasShown.plural ).replace( '%d', registeredAreaCount ); + someRenderedMessage = l10n.noAreasShown; + } + if ( someRenderedMessage ) { + noticeContainer.append( $( '
', { + text: someRenderedMessage + } ) ); } noticeContainer.append( $( '', { - text: message - } ) ); - noticeContainer.append( $( '', { text: l10n.navigatePreview } ) ); } diff --git src/wp-includes/class-wp-customize-widgets.php src/wp-includes/class-wp-customize-widgets.php index 887c11fa0c..45e884f4f1 100644 --- src/wp-includes/class-wp-customize-widgets.php +++ src/wp-includes/class-wp-customize-widgets.php @@ -720,6 +720,47 @@ final class WP_Customize_Widgets { ' ); + /* + * Gather all strings in PHP that may be needed by JS on the client. + * Once JS i18n is implemented (in #20491), this can be removed. + */ + $some_non_rendered_areas_messages = array(); + $some_non_rendered_areas_messages[1] = html_entity_decode( + /* translators: placeholder is the number of other widget areas registered but not rendered */ + __( 'Your theme has 1 other widget area, but this particular page doesn’t display it.' ), + ENT_QUOTES, + get_bloginfo( 'charset' ) + ); + $registered_sidebar_count = count( $wp_registered_sidebars ); + for ( $non_rendered_count = 2; $non_rendered_count < $registered_sidebar_count; $non_rendered_count++ ) { + $some_non_rendered_areas_messages[ $non_rendered_count ] = html_entity_decode( sprintf( + /* translators: placeholder is the number of other widget areas registered but not rendered */ + _n( + 'Your theme has %s other widget area, but this particular page doesn’t display it.', + 'Your theme has %s other widget areas, but this particular page doesn’t display them.', + $non_rendered_count + ), + number_format_i18n( $non_rendered_count ) + ), ENT_QUOTES, get_bloginfo( 'charset' ) ); + } + + if ( 1 === $registered_sidebar_count ) { + $no_areas_shown_message = html_entity_decode( sprintf( + /* translators: placeholder is the total number of widget areas registered */ + __( 'Your theme has 1 widget area, but this particular page doesn’t display it.' ) + ), ENT_QUOTES, get_bloginfo( 'charset' ) ); + } else { + $no_areas_shown_message = html_entity_decode( sprintf( + /* translators: placeholder is the total number of widget areas registered */ + _n( + 'Your theme has %s widget area, but this particular page doesn’t display it.', + 'Your theme has %s widget areas, but this particular page doesn’t display them.', + $registered_sidebar_count + ), + number_format_i18n( $registered_sidebar_count ) + ), ENT_QUOTES, get_bloginfo( 'charset' ) ); + } + $settings = array( 'registeredSidebars' => array_values( $wp_registered_sidebars ), 'registeredWidgets' => $wp_registered_widgets, @@ -733,22 +774,8 @@ final class WP_Customize_Widgets { 'widgetMovedUp' => __( 'Widget moved up' ), 'widgetMovedDown' => __( 'Widget moved down' ), 'navigatePreview' => __( 'You can navigate to other pages on your site while using the Customizer to view and edit the widgets displayed on those pages.' ), - 'someAreasShown' => wp_array_slice_assoc( - /* translators: placeholder is the number of other widget areas registered */ - _n_noop( - 'Your theme has %d other widget area, but this particular page doesn\'t display it.', - 'Your theme has %d other widget areas, but this particular page doesn\'t display them.' - ), - array( 'singular', 'plural' ) - ), - 'noAreasShown' => wp_array_slice_assoc( - /* translators: placeholder is the total number of widget areas registered */ - _n_noop( - 'Your theme has %d widget area, but this particular page doesn\'t display it.', - 'Your theme has %d widget areas, but this particular page doesn\'t display them.' - ), - array( 'singular', 'plural' ) - ), + 'someAreasShown' => $some_non_rendered_areas_messages, + 'noAreasShown' => $no_areas_shown_message, 'reorderModeOn' => __( 'Reorder mode enabled' ), 'reorderModeOff' => __( 'Reorder mode closed' ), 'reorderLabelOn' => esc_attr__( 'Reorder widgets' ), diff --git tests/qunit/fixtures/customize-widgets.js tests/qunit/fixtures/customize-widgets.js index 14d43fb872..cee4c6db13 100644 --- tests/qunit/fixtures/customize-widgets.js +++ tests/qunit/fixtures/customize-widgets.js @@ -48,10 +48,7 @@ window._wpCustomizeWidgetsSettings = { 'l10n': { 'error': 'An error has occurred. Please reload the page and try again.', 'navigatePreview': 'You can navigate to other pages on your site while using the Customizer to view and edit the widgets displayed on those pages.', - 'noAreasShown': { - 'plural': 'Your theme has %d widget areas, but this particular page doesn\'t display them.', - 'singular': 'Your theme has %d widget area, but this particular page doesn\'t display it.' - }, + 'noAreasShown': 'Your theme has 3 widget areas, but this particular page doesn\u2019t display them.', 'noWidgetsFound': 'No widgets found.', 'removeBtnLabel': 'Remove', 'removeBtnTooltip': 'Trash widget by moving it to the inactive widgets sidebar.', @@ -61,8 +58,8 @@ window._wpCustomizeWidgetsSettings = { 'saveBtnLabel': 'Apply', 'saveBtnTooltip': 'Save and preview changes before publishing them.', 'someAreasShown': { - 'plural': 'Your theme has %d other widget areas, but this particular page doesn\'t display them.', - 'singular': 'Your theme has %d other widget area, but this particular page doesn\'t display it.' + '1': 'Your theme has 1 other widget area, but this particular page doesn\u2019t display it.', + '2': 'Your theme has 2 other widget areas, but this particular page doesn\u2019t display them.' }, 'widgetMovedDown': 'Widget moved down', 'widgetMovedUp': 'Widget moved up',