Make WordPress Core


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

I18n for custom taxonomies. Fixes #13357

File:
1 edited

Legend:

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

    r14602 r14614  
    4141
    4242        register_post_type( 'attachment', array(
    43                 'label' => __( 'Media' ),
     43                'labels' => array(
     44                        'name' => __( 'Media' ),
     45                ),
    4446                'public' => true,
    4547                'show_ui' => false,
     
    5456
    5557        register_post_type( 'revision', array(
    56                 'label' => __( 'Revisions' ),
    57                 'singular_label' => __( 'Revision' ),
     58                'labels' => array(
     59                        'name' => __( 'Revisions' ),
     60                        'singular_name' => __( 'Revision' ),
     61                ),
    5862                'public' => false,
    5963                '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
     
    6670
    6771        register_post_type( 'nav_menu_item', array(
    68                 'label' => __( 'Navigation Menu Items' ),
    69                 'singular_label' => __( 'Navigation Menu Item' ),
     72                'labels' => array(
     73                        'name' => __( 'Navigation Menu Items' ),
     74                        'singular_name' => __( 'Navigation Menu Item' ),
     75                ),
    7076                'public' => false,
    7177                'show_ui' => false,
     
    926932 * - not_found - Default is No posts found/No pages found
    927933 * - not_found_in_trash - Default is No posts found in Trash/No pages found in Trash
    928  * - parent - This string isn't used on non-hierarchical types. In hierarchical ones the default is Parent Page:
     934 * - parent_item_colon - This string isn't used on non-hierarchical types. In hierarchical ones the default is Parent Page:
    929935 *
    930936 * Above, the first default value is for non-hierarchical post types (like posts) and the second one is for hierarchical post types (like pages.)
     
    948954                'not_found_in_trash' => array( __('No posts found in Trash'), __('No pages found in Trash') ),
    949955                'view' => array( __('View Post'), __('View Page') ),
    950                 'parent' => array( null, __('Parent Page:') )
     956                'parent_item_colon' => array( null, __('Parent Page:') )
    951957        );
     958        return _get_custom_object_labels( $post_type_object, $nohier_vs_hier_defaults );
     959}
     960
     961/**
     962 * Builds an object with custom-something object (post type, taxonomy) labels out of a custom-something object
     963 *
     964 * @access private
     965 */
     966function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) {
    952967       
    953968        // try to get missing (singular_)?name from older style (singular_)?label member variables
    954969        // we keep that for backwards compatibility
    955970        // TODO: remove in 3.1
    956         if ( !isset( $post_type_object->labels['name'] ) && isset( $post_type_object->label ) ) {
    957                 $post_type_object->labels['name'] = $post_type_object->label;
    958         }
    959         if ( !isset( $post_type_object->labels['singular_name'] ) && isset( $post_type_object->singular_label ) ) {
    960                 $post_type_object->labels['singular_name'] = $post_type_object->singular_label;
     971        if ( !isset( $object->labels['name'] ) && isset( $object->label ) ) {
     972                $object->labels['name'] = $object->label;
     973        }
     974        if ( !isset( $object->labels['singular_name'] ) && isset( $object->singular_label ) ) {
     975                $object->labels['singular_name'] = $object->singular_label;
    961976        }
    962977       
    963         $defaults = array_map( create_function( '$x', $post_type_object->hierarchical? 'return $x[1];' : 'return $x[0];' ), $nohier_vs_hier_defaults );
    964         $labels = array_merge( $defaults, $post_type_object->labels );
    965         return (object)$labels;
     978        if ( !isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) ) {
     979                $object->labels['singular_name'] = $object->labels['name'];
     980        }
     981       
     982        $defaults = array_map( create_function( '$x', $object->hierarchical? 'return $x[1];' : 'return $x[0];' ), $nohier_vs_hier_defaults );
     983        $labels = array_merge( $defaults, $object->labels );
     984        return (object)$labels;
    966985}
    967986
Note: See TracChangeset for help on using the changeset viewer.