[wp-trac] [WordPress Trac] #26746: Avoid translating several times post type and taxonomy default labels

WordPress Trac noreply at wordpress.org
Tue Nov 30 18:39:58 UTC 2021


#26746: Avoid translating several times post type and taxonomy default labels
-------------------------------------------+-----------------------------
 Reporter:  Chouby                         |       Owner:  (none)
     Type:  enhancement                    |      Status:  new
 Priority:  normal                         |   Milestone:  Future Release
Component:  Posts, Post Types              |     Version:  3.0
 Severity:  normal                         |  Resolution:
 Keywords:  has-patch needs-refresh early  |     Focuses:  performance
-------------------------------------------+-----------------------------

Comment (by Chouby):

 The way proposed when the ticket was initiated can't work anymore due to
 the introduction of `switch_to_locale()` since that time.

 In this new patch, I introduce a new class to store the default labels
 once they are translated. The `reset()` method can be called to reset the
 cache.

 NB: I propose to decrease the priority of the functions hooked to
 `change_locale` to make sure that the default labels will be resetted
 before plugins hook to this same action with the default priority (in case
 they need to register their own post types or taxonomies when the locale
 is switched).

 I tested the patch against WP 5.9-alpha-52272. The number of calls to
 `MO::translate_entry()` decreases from 2,296 to 1,207. Comparing
 cachegrind files, they show a time divided by 12 for
 `get_post_type_labels()` and by 4 for `get_taxonomy_label()`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/26746#comment:17>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list