#38218 closed enhancement (duplicate)
Make post type labels work during locale switching
Reported by: | swissspidy | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | needs-patch needs-unit-tests |
Focuses: | Cc: |
Description
This came up while working on #38157 and #26511.
Moving the logic from get_post_type_labels()
into its own class would greatly benefit the efforts made to switch locales. It essentially replaces the post type labels object with a new class that returns the labels on the fly (note: includes tests from #38157). The downside is that labels are never stored in an array but always translated upon request (performance problems?).
What's needed for just-in-time translation (in addition to the current patch) is probably allowing passing a callback instead of an array of labels to the function. The same would need to be done for custom taxonomies and perhaps post statuses.
Attachments (2)
Change History (16)
#3
@
6 years ago
- Keywords needs-patch needs-unit-tests added; has-patch has-unit-tests removed
- Milestone changed from Awaiting Review to Future Release
#4
@
6 years ago
What about the idea for lazy loading the labels via callback function?
Should we do it now, as part of this ticket or new one will be raised?
#5
@
6 years ago
@dontgo2sleep We can explore that in this ticket, but I see one big problem with this approach: it doesn't work for existing plugins.
There are thousands of plugins registering post types and taxonomies out there. In order for things like the toolbar in the user's locale work, we need to solve this in a backward compatible way for all existing plugins.
The adoption rate for the callback variant would be way too slow without any additional benefit.
Also think about documentation, tutorials, etc. These won't be updated using the callback option for a long time.
However, we probably need both to fully solve this. We'll have to see how it goes.
#6
@
6 years ago
@swissspidy I got your point about the adoption of such as feature.
What bothers me is that I am not quite sure about the technical implementation. What is your exact idea about the callback? What I understand is WP_Post_Type object to have property labels pointing to function returning an array of labels and called on demand by WP_Post_Type_Labels::get() method?
#7
@
6 years ago
Yeah so I added a PoC implementation two years ago for such a class: https://core.trac.wordpress.org/attachment/ticket/26511/WP_Post_Type_Labels.diff
I imagined it to work like this:
- Register a new post type A
- Only define the
name
label and letget_post_type_labels()
provide the rest. (This is what many plugins do, in a nutshell) WP_Post_Type::$labels
is a magic method that returns an array containingname
plus any other labels provided on the fly byget_post_type_labels()
, either using aWP_Post_Type_Label
class or something else.- Register a new post type B
- Pass a callback function to
labels
that returns an array with a single key,name
. WP_Post_Type::$labels
is a magic method that returns a merged array of the callback's result + any missing labels fromget_post_type_labels()
. Again, the specifics of that are TBD.
#8
@
6 years ago
- Milestone changed from Future Release to 5.0
- Summary changed from Introduce a WP_Post_Type_Labels class to Make post type labels work during locale switching
#9
@
6 years ago
Just took another stab at this, using a magic getter and callbacks to make things work.
Includes some basic tests for post type labels already.
Note that you need to generate the de_DE.mo
file in the test directory yourself before running the tests.
#10
@
6 years ago
Feels like we should close this in favor of #41305. Somehow I totally forgot about that ticket...
#11
@
6 years ago
- Milestone 5.0 deleted
- Resolution set to duplicate
- Status changed from new to closed
Duplicate of #41305.
In 40635: