Make WordPress Core


Ignore:
Timestamp:
04/04/2022 03:48:08 AM (3 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/taxonomy.php

    r52992 r53058  
    2525function create_initial_taxonomies() {
    2626    global $wp_rewrite;
     27
     28    WP_Taxonomy::reset_default_labels();
    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.