Make WordPress Core


Ignore:
Timestamp:
05/14/2010 12:34:04 AM (15 years ago)
Author:
nbachiyski
Message:

I18n for custom taxonomies. Fixes #13357

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/taxonomy.php

    r14606 r14614  
    1919        'hierarchical' => true,
    2020        'update_count_callback' => '_update_post_term_count',
    21         'label' => __( 'Categories' ),
    22         'singular_label' => __( 'Category' ),
    2321        'query_var' => false,
    2422        'rewrite' => false,
     
    3129        'hierarchical' => false,
    3230        'update_count_callback' => '_update_post_term_count',
    33         'label' => __( 'Post Tags' ),
    34         'singular_label' => __( 'Post Tag' ),
    3531        'query_var' => false,
    3632        'rewrite' => false,
     
    4238    register_taxonomy( 'nav_menu', 'nav_menu_item', array(
    4339        'hierarchical' => false,
    44         'label' => __( 'Navigation Menus' ),
    45         'singular_label' => __( 'Navigation Menu' ),
     40        'labels' => array(
     41            'name' => __( 'Navigation Menus' ),
     42            'singular_name' => __( 'Navigation Menu' ),
     43        ),
    4644        'query_var' => false,
    4745        'rewrite' => false,
     
    5250    register_taxonomy( 'link_category', 'link', array(
    5351        'hierarchical' => false,
    54         'label' => __( 'Categories' ),
     52        'labels' => array(
     53            'name' => __( 'Categories' ),
     54            'singular_name' => __( 'Category' ),
     55        ),
    5556        'query_var' => false,
    5657        'rewrite' => false,
     
    231232 * show_tagcloud - false to prevent the taxonomy being listed in the Tag Cloud Widget;
    232233 * defaults to show_ui which defalts to public.
     234 *
     235 * 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.
    233236 *
    234237 * @package WordPress
     
    255258                        'public' => true,
    256259                        'show_ui' => null,
    257                         'label' => null,
    258260                        'show_tagcloud' => null,
    259261                        '_builtin' => false,
     262                        'labels' => array(),
    260263                        'capabilities' => array(),
    261                         );
     264                    );
    262265    $args = wp_parse_args($args, $defaults);
    263266
     
    283286    if ( is_null($args['show_tagcloud']) )
    284287        $args['show_tagcloud'] = $args['show_ui'];
    285 
    286     if ( is_null($args['label'] ) )
    287         $args['label'] = $taxonomy;
    288288
    289289    $default_caps = array(
     
    296296    unset( $args['capabilities'] );
    297297
    298     if ( empty($args['singular_label']) )
    299         $args['singular_label'] = $args['label'];
    300 
    301298    $args['name'] = $taxonomy;
    302299    $args['object_type'] = (array) $object_type;
     300    $args['labels'] = get_taxonomy_labels( (object) $args );
     301   
     302    // we keep these two only for backwards compatibility
     303    // TODO: remove in 3.1 
     304    $args['label'] = $args['labels']->name;
     305    $args['singular_label'] = $args['labels']->singular_name;
     306   
    303307    $wp_taxonomies[$taxonomy] = (object) $args;
    304308
    305309    // register callback handling for metabox
    306310    add_filter('wp_ajax_add-'.$taxonomy, '_wp_ajax_add_hierarchical_term');
     311}
     312
     313/**
     314 * Builds an object with all taxonomy labels out of a taxonomy object
     315 *
     316 * Accepted keys of the label array in the taxonomy object:
     317 * - name - general name for the taxonomy, usually plural. Default is Post Tags/Categories
     318 * - singular_name - name for one object of this taxonomy. Default is Post Tag/Category
     319 * - search_items - Default is Search Tags/Search Categories
     320 * - popular_items - Default is Popular Tags/Popular Categories
     321 * - all_items - Default is All Tags/All Categories
     322 * - parent_item - This string isn't used on non-hierarchical taxonomies. In hierarchical ones the default is Parent Category
     323 * - parent_item_colon - The same as <code>parent_item</code>, but with colon <code>:</code> in the end
     324 * - edit_item - Default is Edit Tag/Edit Category
     325 * - update_item - Default is Update Tag/Update Category
     326 * - add_new_item - Default is Add New Tag/Add New Category
     327 * - new_item_name - Default is New Tag Name/New Category Name
     328 *
     329 * Above, the first default value is for non-hierarchical taxonomies (like tags) and the second one is for hierarchical taxonomies (like categories.)
     330 *
     331 * @since 3.0.0
     332 * @param object $tax Taxonomy object
     333 * @return object object with all the labels as member variables
     334 */
     335
     336function get_taxonomy_labels( $tax ) {
     337    $nohier_vs_hier_defaults = array(
     338        'name' => array( _x( 'Post Tags', 'taxonomy general name' ), _x( 'Categories', 'taxonomy general name' ) ),
     339        'singular_name' => array( _x( 'Post Tag', 'taxonomy singular name' ), _x( 'Category', 'taxonomy singular name' ) ),
     340        'search_items' => array( __( 'Search Tags' ), __( 'Search Categories' ) ),
     341        'popular_items' => array( __( 'Popular Tags' ), __( 'Popular Category' ) ),
     342        'all_items' => array( __( 'All Tags' ), __( 'All Categories' ) ),
     343        'parent_item' => array( null, __( 'Parent Category' ) ),
     344        'parent_item_colon' => array( null, __( 'Parent Category:' ) ),
     345        'edit_item' => array( __( 'Edit Tag' ), __( 'Edit Category' ) ),
     346        'update_item' => array( __( 'Update Tag' ), __( 'Update Category' ) ),
     347        'add_new_item' => array( __( 'Add New Tag' ), __( 'Add New Category' ) ),
     348        'new_item_name' => array( __( 'New Tag Name' ), __( 'New Category Name' ) ),
     349    );
     350
     351    return _get_custom_object_labels( $tax, $nohier_vs_hier_defaults );
    307352}
    308353
     
    26132658    return false;
    26142659}
    2615 
    2616 
    2617 ?>
Note: See TracChangeset for help on using the changeset viewer.