I18n for custom taxonomies. Fixes #13357

git-svn-id: http://svn.automattic.com/wordpress/trunk@14614 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nbachiyski
2010-05-14 00:34:04 +00:00
parent f06b9dbcf6
commit 4cf46b6d96
15 changed files with 151 additions and 69 deletions

View File

@@ -18,8 +18,6 @@ function create_initial_taxonomies() {
register_taxonomy( 'category', 'post', array(
'hierarchical' => true,
'update_count_callback' => '_update_post_term_count',
'label' => __( 'Categories' ),
'singular_label' => __( 'Category' ),
'query_var' => false,
'rewrite' => false,
'public' => true,
@@ -30,8 +28,6 @@ function create_initial_taxonomies() {
register_taxonomy( 'post_tag', 'post', array(
'hierarchical' => false,
'update_count_callback' => '_update_post_term_count',
'label' => __( 'Post Tags' ),
'singular_label' => __( 'Post Tag' ),
'query_var' => false,
'rewrite' => false,
'public' => true,
@@ -41,8 +37,10 @@ function create_initial_taxonomies() {
register_taxonomy( 'nav_menu', 'nav_menu_item', array(
'hierarchical' => false,
'label' => __( 'Navigation Menus' ),
'singular_label' => __( 'Navigation Menu' ),
'labels' => array(
'name' => __( 'Navigation Menus' ),
'singular_name' => __( 'Navigation Menu' ),
),
'query_var' => false,
'rewrite' => false,
'show_ui' => false,
@@ -51,7 +49,10 @@ function create_initial_taxonomies() {
register_taxonomy( 'link_category', 'link', array(
'hierarchical' => false,
'label' => __( 'Categories' ),
'labels' => array(
'name' => __( 'Categories' ),
'singular_name' => __( 'Category' ),
),
'query_var' => false,
'rewrite' => false,
'public' => false,
@@ -230,6 +231,8 @@ function is_taxonomy_hierarchical($taxonomy) {
*
* show_tagcloud - false to prevent the taxonomy being listed in the Tag Cloud Widget;
* defaults to show_ui which defalts to public.
*
* labels - An array of labels for this taxonomy. You can see accepted values in {@link get_taxonomy_labels()}. By default tag labels are used for non-hierarchical types and category labels for hierarchical ones.
*
* @package WordPress
* @subpackage Taxonomy
@@ -254,11 +257,11 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
'query_var' => $taxonomy,
'public' => true,
'show_ui' => null,
'label' => null,
'show_tagcloud' => null,
'_builtin' => false,
'labels' => array(),
'capabilities' => array(),
);
);
$args = wp_parse_args($args, $defaults);
if ( false !== $args['query_var'] && !empty($wp) ) {
@@ -283,9 +286,6 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
if ( is_null($args['show_tagcloud']) )
$args['show_tagcloud'] = $args['show_ui'];
if ( is_null($args['label'] ) )
$args['label'] = $taxonomy;
$default_caps = array(
'manage_terms' => 'manage_categories',
'edit_terms' => 'manage_categories',
@@ -295,17 +295,62 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
$args['cap'] = (object) array_merge( $default_caps, $args['capabilities'] );
unset( $args['capabilities'] );
if ( empty($args['singular_label']) )
$args['singular_label'] = $args['label'];
$args['name'] = $taxonomy;
$args['object_type'] = (array) $object_type;
$args['labels'] = get_taxonomy_labels( (object) $args );
// we keep these two only for backwards compatibility
// TODO: remove in 3.1
$args['label'] = $args['labels']->name;
$args['singular_label'] = $args['labels']->singular_name;
$wp_taxonomies[$taxonomy] = (object) $args;
// register callback handling for metabox
add_filter('wp_ajax_add-'.$taxonomy, '_wp_ajax_add_hierarchical_term');
}
/**
* Builds an object with all taxonomy labels out of a taxonomy object
*
* Accepted keys of the label array in the taxonomy object:
* - name - general name for the taxonomy, usually plural. Default is Post Tags/Categories
* - singular_name - name for one object of this taxonomy. Default is Post Tag/Category
* - search_items - Default is Search Tags/Search Categories
* - popular_items - Default is Popular Tags/Popular Categories
* - all_items - Default is All Tags/All Categories
* - parent_item - This string isn't used on non-hierarchical taxonomies. In hierarchical ones the default is Parent Category
* - parent_item_colon - The same as <code>parent_item</code>, but with colon <code>:</code> in the end
* - edit_item - Default is Edit Tag/Edit Category
* - update_item - Default is Update Tag/Update Category
* - add_new_item - Default is Add New Tag/Add New Category
* - new_item_name - Default is New Tag Name/New Category Name
*
* Above, the first default value is for non-hierarchical taxonomies (like tags) and the second one is for hierarchical taxonomies (like categories.)
*
* @since 3.0.0
* @param object $tax Taxonomy object
* @return object object with all the labels as member variables
*/
function get_taxonomy_labels( $tax ) {
$nohier_vs_hier_defaults = array(
'name' => array( _x( 'Post Tags', 'taxonomy general name' ), _x( 'Categories', 'taxonomy general name' ) ),
'singular_name' => array( _x( 'Post Tag', 'taxonomy singular name' ), _x( 'Category', 'taxonomy singular name' ) ),
'search_items' => array( __( 'Search Tags' ), __( 'Search Categories' ) ),
'popular_items' => array( __( 'Popular Tags' ), __( 'Popular Category' ) ),
'all_items' => array( __( 'All Tags' ), __( 'All Categories' ) ),
'parent_item' => array( null, __( 'Parent Category' ) ),
'parent_item_colon' => array( null, __( 'Parent Category:' ) ),
'edit_item' => array( __( 'Edit Tag' ), __( 'Edit Category' ) ),
'update_item' => array( __( 'Update Tag' ), __( 'Update Category' ) ),
'add_new_item' => array( __( 'Add New Tag' ), __( 'Add New Category' ) ),
'new_item_name' => array( __( 'New Tag Name' ), __( 'New Category Name' ) ),
);
return _get_custom_object_labels( $tax, $nohier_vs_hier_defaults );
}
/**
* Add an already registered taxonomy to an object type.
*
@@ -2612,6 +2657,3 @@ function is_object_in_taxonomy($object_type, $taxonomy) {
return false;
}
?>