Make WordPress Core

Changeset 53058

Timestamp:
04/04/2022 03:48:08 AM (2 years ago)
Author:
peterwilsoncc
Message:

Posts, Post Types; Taxonomy: Translate default labels once.

Improve the translation of post type and taxonomy labels by caching the translations during runtime. To account for internationalisation plugins, the runtime cache is cleared as the post types/taxonomies are reinitiated on change_local hook.

The same property and methods are added to both WP_Post_Type and WP_Taxonomy:

  • $default_labels: for storing the translated strings at runtime
  • get_default_labels(): for getting the default labels, these are translated on the first run and stored in the new property.
  • reset_default_labels(): to clear the runtime cache and force a re-translation of the default labels

Props Chouby, nacin, SergeyBiryukov, Rarst, chriscct7, ocean90, audrasjb, costdev.
Fixes #26746.

Location:
trunk/src/wp-includes
Files:
4 edited

Legend:

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

    r52652 r53058  
    4444     */
    4545    public $labels;
     46
     47
     48
     49
     50
     51
     52
     53
    4654
    4755    /**
     
    786794        return $this->rest_controller;
    787795    }
     796
     797
     798
     799
     800
     801
     802
     803
     804
     805
     806
     807
     808
     809
     810
     811
     812
     813
     814
     815
     816
     817
     818
     819
     820
     821
     822
     823
     824
     825
     826
     827
     828
     829
     830
     831
     832
     833
     834
     835
     836
     837
     838
     839
     840
     841
     842
     843
     844
     845
     846
     847
     848
     849
     850
     851
     852
     853
     854
     855
     856
     857
     858
     859
     860
    788861}
  • trunk/src/wp-includes/class-wp-taxonomy.php

    r52652 r53058  
    4242     */
    4343    public $labels;
     44
     45
     46
     47
     48
     49
     50
     51
    4452
    4553    /**
     
    563571        return $this->rest_controller;
    564572    }
     573
     574
     575
     576
     577
     578
     579
     580
     581
     582
     583
     584
     585
     586
     587
     588
     589
     590
     591
     592
     593
     594
     595
     596
     597
     598
     599
     600
     601
     602
     603
     604
     605
     606
     607
     608
     609
     610
     611
     612
     613
     614
     615
     616
     617
     618
     619
     620
     621
     622
     623
     624
     625
     626
     627
     628
     629
     630
     631
     632
     633
     634
     635
     636
     637
     638
     639
    565640}
  • trunk/src/wp-includes/post.php

    r53042 r53058  
    1919 */
    2020function create_initial_post_types() {
     21
     22
    2123    register_post_type(
    2224        'post',
     
    19561958 */
    19571959function get_post_type_labels( $post_type_object ) {
    1958     $nohier_vs_hier_defaults = array(
    1959         'name'                     => array( _x( 'Posts', 'post type general name' ), _x( 'Pages', 'post type general name' ) ),
    1960         'singular_name'            => array( _x( 'Post', 'post type singular name' ), _x( 'Page', 'post type singular name' ) ),
    1961         'add_new'                  => array( _x( 'Add New', 'post' ), _x( 'Add New', 'page' ) ),
    1962         'add_new_item'             => array( __( 'Add New Post' ), __( 'Add New Page' ) ),
    1963         'edit_item'                => array( __( 'Edit Post' ), __( 'Edit Page' ) ),
    1964         'new_item'                 => array( __( 'New Post' ), __( 'New Page' ) ),
    1965         'view_item'                => array( __( 'View Post' ), __( 'View Page' ) ),
    1966         'view_items'               => array( __( 'View Posts' ), __( 'View Pages' ) ),
    1967         'search_items'             => array( __( 'Search Posts' ), __( 'Search Pages' ) ),
    1968         'not_found'                => array( __( 'No posts found.' ), __( 'No pages found.' ) ),
    1969         'not_found_in_trash'       => array( __( 'No posts found in Trash.' ), __( 'No pages found in Trash.' ) ),
    1970         'parent_item_colon'        => array( null, __( 'Parent Page:' ) ),
    1971         'all_items'                => array( __( 'All Posts' ), __( 'All Pages' ) ),
    1972         'archives'                 => array( __( 'Post Archives' ), __( 'Page Archives' ) ),
    1973         'attributes'               => array( __( 'Post Attributes' ), __( 'Page Attributes' ) ),
    1974         'insert_into_item'         => array( __( 'Insert into post' ), __( 'Insert into page' ) ),
    1975         'uploaded_to_this_item'    => array( __( 'Uploaded to this post' ), __( 'Uploaded to this page' ) ),
    1976         'featured_image'           => array( _x( 'Featured image', 'post' ), _x( 'Featured image', 'page' ) ),
    1977         'set_featured_image'       => array( _x( 'Set featured image', 'post' ), _x( 'Set featured image', 'page' ) ),
    1978         'remove_featured_image'    => array( _x( 'Remove featured image', 'post' ), _x( 'Remove featured image', 'page' ) ),
    1979         'use_featured_image'       => array( _x( 'Use as featured image', 'post' ), _x( 'Use as featured image', 'page' ) ),
    1980         'filter_items_list'        => array( __( 'Filter posts list' ), __( 'Filter pages list' ) ),
    1981         'filter_by_date'           => array( __( 'Filter by date' ), __( 'Filter by date' ) ),
    1982         'items_list_navigation'    => array( __( 'Posts list navigation' ), __( 'Pages list navigation' ) ),
    1983         'items_list'               => array( __( 'Posts list' ), __( 'Pages list' ) ),
    1984         'item_published'           => array( __( 'Post published.' ), __( 'Page published.' ) ),
    1985         'item_published_privately' => array( __( 'Post published privately.' ), __( 'Page published privately.' ) ),
    1986         'item_reverted_to_draft'   => array( __( 'Post reverted to draft.' ), __( 'Page reverted to draft.' ) ),
    1987         'item_scheduled'           => array( __( 'Post scheduled.' ), __( 'Page scheduled.' ) ),
    1988         'item_updated'             => array( __( 'Post updated.' ), __( 'Page updated.' ) ),
    1989         'item_link'                => array(
    1990             _x( 'Post Link', 'navigation link block title' ),
    1991             _x( 'Page Link', 'navigation link block title' ),
    1992         ),
    1993         'item_link_description'    => array(
    1994             _x( 'A link to a post.', 'navigation link block description' ),
    1995             _x( 'A link to a page.', 'navigation link block description' ),
    1996         ),
    1997     );
     1960    $nohier_vs_hier_defaults = WP_Post_Type::get_default_labels();
    19981961
    19991962    $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name'];
  • trunk/src/wp-includes/taxonomy.php

    r52992 r53058  
    2525function create_initial_taxonomies() {
    2626    global $wp_rewrite;
     27
     28
    2729
    2830    if ( ! did_action( 'init' ) ) {
     
    660662    }
    661663
    662     $name_field_description   = __( 'The name is how it appears on your site.' );
    663     $slug_field_description   = __( 'The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.' );
    664     $parent_field_description = __( 'Assign a parent term to create a hierarchy. The term Jazz, for example, would be the parent of Bebop and Big Band.' );
    665     $desc_field_description   = __( 'The description is not prominent by default; however, some themes may show it.' );
    666 
    667     $nohier_vs_hier_defaults = array(
    668         'name'                       => array( _x( 'Tags', 'taxonomy general name' ), _x( 'Categories', 'taxonomy general name' ) ),
    669         'singular_name'              => array( _x( 'Tag', 'taxonomy singular name' ), _x( 'Category', 'taxonomy singular name' ) ),
    670         'search_items'               => array( __( 'Search Tags' ), __( 'Search Categories' ) ),
    671         'popular_items'              => array( __( 'Popular Tags' ), null ),
    672         'all_items'                  => array( __( 'All Tags' ), __( 'All Categories' ) ),
    673         'parent_item'                => array( null, __( 'Parent Category' ) ),
    674         'parent_item_colon'          => array( null, __( 'Parent Category:' ) ),
    675         'name_field_description'     => array( $name_field_description, $name_field_description ),
    676         'slug_field_description'     => array( $slug_field_description, $slug_field_description ),
    677         'parent_field_description'   => array( null, $parent_field_description ),
    678         'desc_field_description'     => array( $desc_field_description, $desc_field_description ),
    679         'edit_item'                  => array( __( 'Edit Tag' ), __( 'Edit Category' ) ),
    680         'view_item'                  => array( __( 'View Tag' ), __( 'View Category' ) ),
    681         'update_item'                => array( __( 'Update Tag' ), __( 'Update Category' ) ),
    682         'add_new_item'               => array( __( 'Add New Tag' ), __( 'Add New Category' ) ),
    683         'new_item_name'              => array( __( 'New Tag Name' ), __( 'New Category Name' ) ),
    684         'separate_items_with_commas' => array( __( 'Separate tags with commas' ), null ),
    685         'add_or_remove_items'        => array( __( 'Add or remove tags' ), null ),
    686         'choose_from_most_used'      => array( __( 'Choose from the most used tags' ), null ),
    687         'not_found'                  => array( __( 'No tags found.' ), __( 'No categories found.' ) ),
    688         'no_terms'                   => array( __( 'No tags' ), __( 'No categories' ) ),
    689         'filter_by_item'             => array( null, __( 'Filter by category' ) ),
    690         'items_list_navigation'      => array( __( 'Tags list navigation' ), __( 'Categories list navigation' ) ),
    691         'items_list'                 => array( __( 'Tags list' ), __( 'Categories list' ) ),
    692         /* translators: Tab heading when selecting from the most used terms. */
    693         'most_used'                  => array( _x( 'Most Used', 'tags' ), _x( 'Most Used', 'categories' ) ),
    694         'back_to_items'              => array( __( '← Go to Tags' ), __( '← Go to Categories' ) ),
    695         'item_link'                  => array(
    696             _x( 'Tag Link', 'navigation link block title' ),
    697             _x( 'Category Link', 'navigation link block title' ),
    698         ),
    699         'item_link_description'      => array(
    700             _x( 'A link to a tag.', 'navigation link block description' ),
    701             _x( 'A link to a category.', 'navigation link block description' ),
    702         ),
    703     );
     664    $nohier_vs_hier_defaults = WP_Taxonomy::get_default_labels();
    704665
    705666    $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name'];
Note: See TracChangeset for help on using the changeset viewer.