Allow localized commas to be used as tag separators. see #7897.

git-svn-id: http://svn.automattic.com/wordpress/trunk@19853 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2012-02-07 18:06:12 +00:00
parent 86596214bd
commit 72c995441a
9 changed files with 59 additions and 26 deletions

View File

@ -66,6 +66,9 @@ function wp_ajax_ajax_tag_search() {
$s = stripslashes( $_GET['q'] );
$comma = _x( ',', 'tag delimiter' );
if ( ',' !== $comma )
$s = str_replace( $comma, ',', $s );
if ( false !== strpos( $s, ',' ) ) {
$s = explode( ',', $s );
$s = $s[count( $s ) - 1];

View File

@ -609,7 +609,8 @@ class WP_Posts_List_Table extends WP_List_Table {
esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'category', 'display' ) )
);
}
echo join( ', ', $out );
/* translators: used between list items, there is a space after the comma */
echo join( __( ', ' ), $out );
} else {
_e( 'Uncategorized' );
}
@ -629,7 +630,8 @@ class WP_Posts_List_Table extends WP_List_Table {
esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'tag', 'display' ) )
);
}
echo join( ', ', $out );
/* translators: used between list items, there is a space after the comma */
echo join( __( ', ' ), $out );
} else {
_e( 'No Tags' );
}

View File

@ -276,12 +276,13 @@ function post_tags_meta_box($post, $box) {
$tax_name = esc_attr($taxonomy);
$taxonomy = get_taxonomy($taxonomy);
$disabled = !current_user_can($taxonomy->cap->assign_terms) ? 'disabled="disabled"' : '';
$comma = _x( ',', 'tag delimiter' );
?>
<div class="tagsdiv" id="<?php echo $tax_name; ?>">
<div class="jaxtag">
<div class="nojs-tags hide-if-js">
<p><?php echo $taxonomy->labels->add_or_remove_items; ?></p>
<textarea name="<?php echo "tax_input[$tax_name]"; ?>" rows="3" cols="20" class="the-tags" id="tax-input-<?php echo $tax_name; ?>" <?php echo $disabled; ?>><?php echo get_terms_to_edit( $post->ID, $tax_name ); // textarea_escaped by esc_attr() ?></textarea></div>
<textarea name="<?php echo "tax_input[$tax_name]"; ?>" rows="3" cols="20" class="the-tags" id="tax-input-<?php echo $tax_name; ?>" <?php echo $disabled; ?>><?php echo str_replace( ',', $comma . ' ', get_terms_to_edit( $post->ID, $tax_name ) ); // textarea_escaped by esc_attr() ?></textarea></div>
<?php if ( current_user_can($taxonomy->cap->assign_terms) ) : ?>
<div class="ajaxtag hide-if-no-js">
<label class="screen-reader-text" for="new-tag-<?php echo $tax_name; ?>"><?php echo $box['title']; ?></label>

View File

@ -302,10 +302,12 @@ function bulk_edit_posts( $post_data = null ) {
if ( empty($terms) )
continue;
if ( is_taxonomy_hierarchical( $tax_name ) ) {
$tax_input[$tax_name] = array_map( 'absint', $terms );
$tax_input[ $tax_name ] = array_map( 'absint', $terms );
} else {
$tax_input[$tax_name] = preg_replace( '/\s*,\s*/', ',', rtrim( trim($terms), ' ,' ) );
$tax_input[$tax_name] = explode(',', $tax_input[$tax_name]);
$comma = _x( ',', 'tag delimiter' );
if ( ',' !== $comma )
$terms = str_replace( $comma, ',', $terms );
$tax_input[ $tax_name ] = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
}
}
}

View File

@ -264,10 +264,13 @@ function get_inline_data($post) {
foreach ( $taxonomy_names as $taxonomy_name) {
$taxonomy = get_taxonomy( $taxonomy_name );
if ( $taxonomy->hierarchical && $taxonomy->show_ui )
echo '<div class="post_category" id="'.$taxonomy_name.'_'.$post->ID.'">' . implode( ',', wp_get_object_terms( $post->ID, $taxonomy_name, array('fields'=>'ids')) ) . '</div>';
elseif ( $taxonomy->show_ui )
echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">' . esc_html( str_replace( ',', ', ', get_terms_to_edit($post->ID, $taxonomy_name) ) ) . '</div>';
if ( $taxonomy->hierarchical && $taxonomy->show_ui ) {
echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">'
. implode( ',', wp_get_object_terms( $post->ID, $taxonomy_name, array( 'fields' => 'ids' ) ) ) . '</div>';
} elseif ( $taxonomy->show_ui ) {
echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">'
. esc_html( str_replace( ',', ', ', get_terms_to_edit( $post->ID, $taxonomy_name ) ) ) . '</div>';
}
}
if ( !$post_type_object->hierarchical )

View File

@ -117,7 +117,7 @@ inlineEditPost = {
if ( 'post' == type ) {
// support multi taxonomies?
tax = 'post_tag';
$('tr.inline-editor textarea[name="tax_input['+tax+']"]').suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+tax, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
$('tr.inline-editor textarea[name="tax_input['+tax+']"]').suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+tax, { delay: 500, minchars: 2, multiple: true, multipleSep: inlineEditL10n.comma + ' ' } );
}
$('html, body').animate( { scrollTop: 0 }, 'fast' );
},
@ -184,12 +184,16 @@ inlineEditPost = {
$('.tags_input', rowData).each(function(){
var terms = $(this).text(),
taxname = $(this).attr('id').replace('_' + id, ''),
textarea = $('textarea.tax_input_' + taxname, editRow);
textarea = $('textarea.tax_input_' + taxname, editRow),
comma = inlineEditL10n.comma;
if ( terms )
if ( terms ) {
if ( ',' !== comma )
terms = terms.replace(/,/g, comma);
textarea.val(terms);
}
textarea.suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+taxname, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
textarea.suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+taxname, { delay: 500, minchars: 2, multiple: true, multipleSep: inlineEditL10n.comma + ' ' } );
});
// handle the post status

View File

@ -15,11 +15,19 @@ function array_unique_noempty(a) {
tagBox = {
clean : function(tags) {
return tags.replace(/\s*,\s*/g, ',').replace(/,+/g, ',').replace(/[,\s]+$/, '').replace(/^[,\s]+/, '');
var comma = postL10n.comma;
if ( ',' !== comma )
tags = tags.replace(new RegExp(comma, 'g'), ',');
tags = tags.replace(/\s*,\s*/g, ',').replace(/,+/g, ',').replace(/[,\s]+$/, '').replace(/^[,\s]+/, '');
if ( ',' !== comma )
tags = tags.replace(/,/g, comma);
return tags;
},
parseTags : function(el) {
var id = el.id, num = id.split('-check-num-')[1], taxbox = $(el).closest('.tagsdiv'), thetags = taxbox.find('.the-tags'), current_tags = thetags.val().split(','), new_tags = [];
var id = el.id, num = id.split('-check-num-')[1], taxbox = $(el).closest('.tagsdiv'),
thetags = taxbox.find('.the-tags'), comma = postL10n.comma,
current_tags = thetags.val().split(comma), new_tags = [];
delete current_tags[num];
$.each( current_tags, function(key, val) {
@ -29,7 +37,7 @@ tagBox = {
}
});
thetags.val( this.clean( new_tags.join(',') ) );
thetags.val( this.clean( new_tags.join(comma) ) );
this.quickClicks(taxbox);
return false;
@ -46,7 +54,7 @@ tagBox = {
disabled = thetags.prop('disabled');
current_tags = thetags.val().split(',');
current_tags = thetags.val().split(postL10n.comma);
tagchecklist.empty();
$.each( current_tags, function( key, val ) {
@ -74,14 +82,17 @@ tagBox = {
flushTags : function(el, a, f) {
a = a || false;
var text, tags = $('.the-tags', el), newtag = $('input.newtag', el), newtags;
var tags = $('.the-tags', el),
newtag = $('input.newtag', el),
comma = postL10n.comma,
newtags, text;
text = a ? $(a).text() : newtag.val();
tagsval = tags.val();
newtags = tagsval ? tagsval + ',' + text : text;
newtags = tagsval ? tagsval + comma + text : text;
newtags = this.clean( newtags );
newtags = array_unique_noempty( newtags.split(',') ).join(',');
newtags = array_unique_noempty( newtags.split(comma) ).join(comma);
tags.val(newtags);
this.quickClicks(el);
@ -96,7 +107,7 @@ tagBox = {
get : function(id) {
var tax = id.substr(id.indexOf('-')+1);
$.post(ajaxurl, {'action':'get-tagcloud','tax':tax}, function(r, stat) {
$.post(ajaxurl, {'action':'get-tagcloud', 'tax':tax}, function(r, stat) {
if ( 0 == r || 'success' != stat )
r = wpAjax.broken;
@ -142,7 +153,7 @@ tagBox = {
}
}).each(function(){
var tax = $(this).closest('div.tagsdiv').attr('id');
$(this).suggest( ajaxurl + '?action=ajax-tag-search&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: "," } );
$(this).suggest( ajaxurl + '?action=ajax-tag-search&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: postL10n.comma + ' ' } );
});
// save tags on post save/publish

View File

@ -2907,7 +2907,12 @@ function wp_set_post_terms( $post_id = 0, $tags = '', $taxonomy = 'post_tag', $a
if ( empty($tags) )
$tags = array();
$tags = is_array($tags) ? $tags : explode( ',', trim($tags, " \n\t\r\0\x0B,") );
if ( ! is_array( $tags ) ) {
$comma = _x( ',', 'tag delimiter' );
if ( ',' !== $comma )
$tags = str_replace( $comma, ',', $tags );
$tags = explode( ',', trim( $tags, " \n\t\r\0\x0B," ) );
}
// Hierarchical taxonomies must always pass IDs rather than names so that children with the same
// names but different parents aren't confused.

View File

@ -330,7 +330,8 @@ function wp_default_scripts( &$scripts ) {
'publicSticky' => __('Public, Sticky'),
'password' => __('Password Protected'),
'privatelyPublished' => __('Privately Published'),
'published' => __('Published')
'published' => __('Published'),
'comma' => _x( ',', 'tag delimiter' ),
) );
$scripts->add( 'link', "/wp-admin/js/link$suffix.js", array('wp-lists', 'postbox'), false, 1 );
@ -353,7 +354,8 @@ function wp_default_scripts( &$scripts ) {
$scripts->localize( 'inline-edit-post', 'inlineEditL10n', array(
'error' => __('Error while saving the changes.'),
'ntdeltitle' => __('Remove From Bulk Edit'),
'notitle' => __('(no title)')
'notitle' => __('(no title)'),
'comma' => _x( ',', 'tag delimiter' ),
) );
$scripts->add( 'inline-edit-tax', "/wp-admin/js/inline-edit-tax$suffix.js", array( 'jquery' ), false, 1 );