I18N: Fix plural usage in wp_print_admin_notice_templates().

Moves the translatable strings from the JS template defined in PHP to the `updates.js` script, where `_n()` can be used as recommended.

Props ideag, SergeyBiryukov, daledupreez, audrasjb, ocean90, swissspidy.
Fixes #37287.
Built from https://develop.svn.wordpress.org/trunk@58064


git-svn-id: http://core.svn.wordpress.org/trunk@57529 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Pascal Birchler 2024-04-30 08:55:04 +00:00
parent 417862e504
commit b2da8bbcc9
4 changed files with 40 additions and 46 deletions

View File

@ -923,48 +923,14 @@ function wp_print_admin_notice_templates() {
<div <# if ( data.id ) { #>id="{{ data.id }}"<# } #> class="notice {{ data.className }}"><p>{{{ data.message }}}</p></div>
</script>
<script id="tmpl-wp-bulk-updates-admin-notice" type="text/html">
<div id="{{ data.id }}" class="{{ data.className }} notice <# if ( data.errors ) { #>notice-error<# } else { #>notice-success<# } #>">
<div id="{{ data.id }}" class="{{ data.className }} notice <# if ( data.errorMessage ) { #>notice-error<# } else { #>notice-success<# } #>">
<p>
<# if ( data.successes ) { #>
<# if ( 1 === data.successes ) { #>
<# if ( 'plugin' === data.type ) { #>
<?php
/* translators: %s: Number of plugins. */
printf( __( '%s plugin successfully updated.' ), '{{ data.successes }}' );
?>
<# } else { #>
<?php
/* translators: %s: Number of themes. */
printf( __( '%s theme successfully updated.' ), '{{ data.successes }}' );
?>
<# } #>
<# } else { #>
<# if ( 'plugin' === data.type ) { #>
<?php
/* translators: %s: Number of plugins. */
printf( __( '%s plugins successfully updated.' ), '{{ data.successes }}' );
?>
<# } else { #>
<?php
/* translators: %s: Number of themes. */
printf( __( '%s themes successfully updated.' ), '{{ data.successes }}' );
?>
<# } #>
<# } #>
<# if ( data.successMessage ) { #>
{{{ data.successMessage }}}
<# } #>
<# if ( data.errors ) { #>
<# if ( data.errorMessage ) { #>
<button class="button-link bulk-action-errors-collapsed" aria-expanded="false">
<# if ( 1 === data.errors ) { #>
<?php
/* translators: %s: Number of failed updates. */
printf( __( '%s update failed.' ), '{{ data.errors }}' );
?>
<# } else { #>
<?php
/* translators: %s: Number of failed updates. */
printf( __( '%s updates failed.' ), '{{ data.errors }}' );
?>
<# } #>
{{{ data.errorMessage }}}
<span class="screen-reader-text">
<?php
/* translators: Hidden accessibility text. */
@ -975,7 +941,7 @@ function wp_print_admin_notice_templates() {
</button>
<# } #>
</p>
<# if ( data.errors ) { #>
<# if ( data.errorMessages ) { #>
<ul class="bulk-action-errors hidden">
<# _.each( data.errorMessages, function( errorMessage ) { #>
<li>{{ errorMessage }}</li>

View File

@ -2938,13 +2938,41 @@
wp.updates.adminNotice = wp.template( 'wp-bulk-updates-admin-notice' );
var successMessage = null;
if ( success ) {
if ( 'plugin' === response.update ) {
successMessage = sprintf(
/* translators: %s: Number of plugins. */
_n( '%s plugin successfully updated.', '%s plugins successfully updated.', success ),
success
);
} else {
successMessage = sprintf(
/* translators: %s: Number of themes. */
_n( '%s theme successfully updated.', '%s themes successfully updated.', success ),
success
);
}
}
var errorMessage = null;
if ( error ) {
errorMessage = sprintf(
/* translators: %s: Number of failed updates. */
_n( '%s update failed.', '%s updates failed.', error ),
error
);
}
wp.updates.addAdminNotice( {
id: 'bulk-action-notice',
className: 'bulk-action-notice',
successes: success,
errors: error,
errorMessages: errorMessages,
type: response.update
successMessage: successMessage,
errorMessage: errorMessage,
errorMessages: errorMessages,
type: response.update
} );
$bulkActionNotice = $( '#bulk-action-notice' ).on( 'click', 'button', function() {

File diff suppressed because one or more lines are too long

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.6-alpha-58063';
$wp_version = '6.6-alpha-58064';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.