Make WordPress Core


Ignore:
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.

File:
1 edited

Legend:

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

    r53042 r53058  
    1919 */
    2020function create_initial_post_types() {
     21    WP_Post_Type::reset_default_labels();
     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'];
Note: See TracChangeset for help on using the changeset viewer.