From 72c995441ad394453033d082a76a35cca49a3d9c Mon Sep 17 00:00:00 2001 From: nacin Date: Tue, 7 Feb 2012 18:06:12 +0000 Subject: [PATCH] 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 --- wp-admin/includes/ajax-actions.php | 3 ++ .../includes/class-wp-posts-list-table.php | 6 ++-- wp-admin/includes/meta-boxes.php | 3 +- wp-admin/includes/post.php | 8 +++-- wp-admin/includes/template.php | 11 ++++--- wp-admin/js/inline-edit-post.dev.js | 12 +++++--- wp-admin/js/post.dev.js | 29 +++++++++++++------ wp-includes/post.php | 7 ++++- wp-includes/script-loader.php | 6 ++-- 9 files changed, 59 insertions(+), 26 deletions(-) diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index a6e1fa724e..f601ecfbf0 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -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]; diff --git a/wp-admin/includes/class-wp-posts-list-table.php b/wp-admin/includes/class-wp-posts-list-table.php index 0f148fa482..5e280e8079 100644 --- a/wp-admin/includes/class-wp-posts-list-table.php +++ b/wp-admin/includes/class-wp-posts-list-table.php @@ -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' ); } diff --git a/wp-admin/includes/meta-boxes.php b/wp-admin/includes/meta-boxes.php index 1a438732b1..d989378d64 100644 --- a/wp-admin/includes/meta-boxes.php +++ b/wp-admin/includes/meta-boxes.php @@ -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' ); ?>

labels->add_or_remove_items; ?>

-
+
cap->assign_terms) ) : ?>
diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index d68285c981..72a3be789e 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -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," ) ); } } } diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index e9b6574bb2..b0865a9c0a 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -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 ''; - elseif ( $taxonomy->show_ui ) - echo '
' . esc_html( str_replace( ',', ', ', get_terms_to_edit($post->ID, $taxonomy_name) ) ) . '
'; + if ( $taxonomy->hierarchical && $taxonomy->show_ui ) { + echo ''; + } elseif ( $taxonomy->show_ui ) { + echo '
' + . esc_html( str_replace( ',', ', ', get_terms_to_edit( $post->ID, $taxonomy_name ) ) ) . '
'; + } } if ( !$post_type_object->hierarchical ) diff --git a/wp-admin/js/inline-edit-post.dev.js b/wp-admin/js/inline-edit-post.dev.js index e73c4a0099..adebb4f5ab 100644 --- a/wp-admin/js/inline-edit-post.dev.js +++ b/wp-admin/js/inline-edit-post.dev.js @@ -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 diff --git a/wp-admin/js/post.dev.js b/wp-admin/js/post.dev.js index dd038d8983..ac6aafb01e 100644 --- a/wp-admin/js/post.dev.js +++ b/wp-admin/js/post.dev.js @@ -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 diff --git a/wp-includes/post.php b/wp-includes/post.php index 2bdd51ba1f..062b70a447 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -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. diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 83cc09e7f2..3201e72f6e 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -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 );