I18N: Use wp.i18n
for translatable strings in wp-admin/js/tags-box.js
and wp-admin/js/tags-suggest.js
.
This removes the usage of `wp_localize_script()` for passing translations to the script and instead adds the translatable strings in the script directly through the use of `wp.i18n` and its utilities. Props swissspidy, ocean90. See #20491. Fixes #50579. git-svn-id: https://develop.svn.wordpress.org/trunk@48350 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
9e29ffdd33
commit
7a59fefb21
@ -6,7 +6,7 @@
|
||||
/* global ajaxurl, tagBox, array_unique_noempty */
|
||||
|
||||
( function( $ ) {
|
||||
var tagDelimiter = ( window.tagsSuggestL10n && window.tagsSuggestL10n.tagDelimiter ) || ',';
|
||||
var tagDelimiter = wp.i18n._x( ',', 'tag delimiter' ) || ',';
|
||||
|
||||
/**
|
||||
* Filters unique items and returns a new array.
|
||||
@ -164,7 +164,7 @@
|
||||
*/
|
||||
xbutton = $( '<button type="button" id="' + id + '-check-num-' + key + '" class="ntdelbutton">' +
|
||||
'<span class="remove-tag-icon" aria-hidden="true"></span>' +
|
||||
'<span class="screen-reader-text">' + window.tagsSuggestL10n.removeTerm + ' ' + listItem.html() + '</span>' +
|
||||
'<span class="screen-reader-text">' + wp.i18n.__( 'Remove term:' ) + ' ' + listItem.html() + '</span>' +
|
||||
'</button>' );
|
||||
|
||||
/**
|
||||
@ -334,11 +334,11 @@
|
||||
|
||||
switch ( this.userAction ) {
|
||||
case 'remove':
|
||||
message = window.tagsSuggestL10n.termRemoved;
|
||||
message = wp.i18n.__( 'Term removed.' );
|
||||
break;
|
||||
|
||||
case 'add':
|
||||
message = window.tagsSuggestL10n.termAdded;
|
||||
message = wp.i18n.__( 'Term added.' );
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -4,12 +4,12 @@
|
||||
* @output wp-admin/js/tags-suggest.js
|
||||
*/
|
||||
( function( $ ) {
|
||||
if ( typeof window.tagsSuggestL10n === 'undefined' || typeof window.uiAutocompleteL10n === 'undefined' ) {
|
||||
if ( typeof window.uiAutocompleteL10n === 'undefined' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var tempID = 0;
|
||||
var separator = window.tagsSuggestL10n.tagDelimiter || ',';
|
||||
var separator = wp.i18n._x( ',', 'tag delimiter' ) || ',';
|
||||
|
||||
function split( val ) {
|
||||
return val.split( new RegExp( separator + '\\s*' ) );
|
||||
@ -104,7 +104,7 @@
|
||||
|
||||
if ( $.ui.keyCode.TAB === event.keyCode ) {
|
||||
// Audible confirmation message when a tag has been selected.
|
||||
window.wp.a11y.speak( window.tagsSuggestL10n.termSelected, 'assertive' );
|
||||
window.wp.a11y.speak( wp.i18n.__( 'Term selected.' ), 'assertive' );
|
||||
event.preventDefault();
|
||||
} else if ( $.ui.keyCode.ENTER === event.keyCode ) {
|
||||
// If we're in the edit post Tags meta box, add the tag.
|
||||
|
@ -1212,19 +1212,10 @@ function wp_default_scripts( $scripts ) {
|
||||
$scripts->set_translations( 'postbox' );
|
||||
|
||||
$scripts->add( 'tags-box', "/wp-admin/js/tags-box$suffix.js", array( 'jquery', 'tags-suggest' ), false, 1 );
|
||||
$scripts->set_translations( 'tags-box' );
|
||||
|
||||
$scripts->add( 'tags-suggest', "/wp-admin/js/tags-suggest$suffix.js", array( 'jquery-ui-autocomplete', 'wp-a11y' ), false, 1 );
|
||||
did_action( 'init' ) && $scripts->localize(
|
||||
'tags-suggest',
|
||||
'tagsSuggestL10n',
|
||||
array(
|
||||
'tagDelimiter' => _x( ',', 'tag delimiter' ),
|
||||
'removeTerm' => __( 'Remove term:' ),
|
||||
'termSelected' => __( 'Term selected.' ),
|
||||
'termAdded' => __( 'Term added.' ),
|
||||
'termRemoved' => __( 'Term removed.' ),
|
||||
)
|
||||
);
|
||||
$scripts->set_translations( 'tags-suggest' );
|
||||
|
||||
$scripts->add( 'post', "/wp-admin/js/post$suffix.js", array( 'suggest', 'wp-lists', 'postbox', 'tags-box', 'underscore', 'word-count', 'wp-a11y', 'wp-sanitize', 'clipboard' ), false, 1 );
|
||||
$scripts->set_translations( 'post' );
|
||||
|
Loading…
Reference in New Issue
Block a user