I18N: Fix passing singular/plural strings to JS.

This is a temporary solution while waiting for full I18N support in JS.

Props ocean90, dd32, westonruter, Mirucon for testing.
Amends [41376], [41721], [41389],
See #20491.
Fixes #42510 for trunk.

Built from https://develop.svn.wordpress.org/trunk@42163


git-svn-id: http://core.svn.wordpress.org/trunk@41994 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2017-11-13 07:08:47 +00:00
parent 6d2bf4398c
commit 4e320fe008
3 changed files with 17 additions and 13 deletions

View File

@ -476,10 +476,11 @@ function wp_default_scripts( &$scripts ) {
did_action( 'init' ) && $scripts->add_inline_script( 'wp-theme-plugin-editor', sprintf( 'wp.themePluginEditor.l10n = %s;', wp_json_encode( array( did_action( 'init' ) && $scripts->add_inline_script( 'wp-theme-plugin-editor', sprintf( 'wp.themePluginEditor.l10n = %s;', wp_json_encode( array(
'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ), 'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ),
'saveError' => __( 'Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over FTP.' ), 'saveError' => __( 'Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over FTP.' ),
'lintError' => wp_array_slice_assoc( 'lintError' => array(
/* translators: %d: error count */ /* translators: %d: error count */
_n_noop( 'There is %d error which must be fixed before you can update this file.', 'There are %d errors which must be fixed before you can update this file.' ), 'singular' => _n( 'There is %d error which must be fixed before you can update this file.', 'There are %d errors which must be fixed before you can update this file.', 1 ),
array( 'singular', 'plural' ) /* translators: %d: error count */
'plural' => _n( 'There is %d error which must be fixed before you can update this file.', 'There are %d errors which must be fixed before you can update this file.', 2 ), // @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491.
), ),
) ) ) ); ) ) ) );
@ -580,16 +581,18 @@ function wp_default_scripts( &$scripts ) {
'videoHeaderNotice' => __( 'This theme doesn’t support video headers on this page. Navigate to the front page or another page that supports video headers.' ), 'videoHeaderNotice' => __( 'This theme doesn’t support video headers on this page. Navigate to the front page or another page that supports video headers.' ),
// Used for overriding the file types allowed in plupload. // Used for overriding the file types allowed in plupload.
'allowedFiles' => __( 'Allowed Files' ), 'allowedFiles' => __( 'Allowed Files' ),
'customCssError' => wp_array_slice_assoc( 'customCssError' => array(
/* translators: %d: error count */ /* translators: %d: error count */
_n_noop( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.' ), 'singular' => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 1 ),
array( 'singular', 'plural' ) /* translators: %d: error count */
'plural' => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 2 ), // @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491.
), ),
'pageOnFrontError' => __( 'Homepage and posts page must be different.' ), 'pageOnFrontError' => __( 'Homepage and posts page must be different.' ),
'saveBlockedError' => wp_array_slice_assoc( 'saveBlockedError' => array(
/* translators: %s: number of invalid settings */ /* translators: %s: number of invalid settings */
_n_noop( 'Unable to save due to %s invalid setting.', 'Unable to save due to %s invalid settings.' ), 'singular' => _n( 'Unable to save due to %s invalid setting.', 'Unable to save due to %s invalid settings.', 1 ),
array( 'singular', 'plural' ) /* translators: %s: number of invalid settings */
'plural' => _n( 'Unable to save due to %s invalid setting.', 'Unable to save due to %s invalid settings.', 2 ), // @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491.
), ),
'scheduleDescription' => __( 'Schedule your customization changes to publish ("go live") at a future date.' ), 'scheduleDescription' => __( 'Schedule your customization changes to publish ("go live") at a future date.' ),
'themePreviewUnavailable' => __( 'Sorry, you can’t preview new themes when you have changes scheduled or saved as a draft. Please publish your changes, or wait until they publish to preview new themes.' ), 'themePreviewUnavailable' => __( 'Sorry, you can’t preview new themes when you have changes scheduled or saved as a draft. Please publish your changes, or wait until they publish to preview new themes.' ),

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.0-alpha-42161'; $wp_version = '5.0-alpha-42163';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -175,10 +175,11 @@ class WP_Widget_Custom_HTML extends WP_Widget {
wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.init( %s );', wp_json_encode( $settings ) ), 'after' ); wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.init( %s );', wp_json_encode( $settings ) ), 'after' );
$l10n = array( $l10n = array(
'errorNotice' => wp_array_slice_assoc( 'errorNotice' => array(
/* translators: %d: error count */ /* translators: %d: error count */
_n_noop( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.' ), 'singular' => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 1 ),
array( 'singular', 'plural' ) /* translators: %d: error count */
'plural' => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 2 ), // @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491.
), ),
); );
wp_add_inline_script( 'custom-html-widgets', sprintf( 'jQuery.extend( wp.customHtmlWidgets.l10n, %s );', wp_json_encode( $l10n ) ), 'after' ); wp_add_inline_script( 'custom-html-widgets', sprintf( 'jQuery.extend( wp.customHtmlWidgets.l10n, %s );', wp_json_encode( $l10n ) ), 'after' );