Automattic / babble

Multilingual WordPress done right.
https://wordpress.org/plugins/babble/
245 stars 50 forks source link

Post types with names over 14 characters, taxonomy names over 26 characters #247

Closed simonwheatley closed 9 years ago

simonwheatley commented 9 years ago

When registering a translated (shadow) post type in Babble_Post_Public::registered_post_type, if a post_type string is longer than 14 characters, and the language is two two letter codes, then WordPress register_post_type will return a WP_Error and trigger a _doing_it_wrong_call, e.g. post type 012345678912345 would become a translated post type 012345678912345_xx_xx (21 characters long) which would cause the issue described.

We should:

  1. Change where we are currently calling trigger_error (or throw new exception) to instead call _doing_it_wrong
  2. wp_die if WP_DEBUG is defined and true, or throw an admin notice if not
  3. Stretch goal: Do not allow any translation of a post type if one of the translation post types for it will go over 20 characters

There is a similar problem with taxonomy names, except the limit is 26 characters (32 characters minus the six characters we need for the lang code suffix), which we should address in a similar way.

joehoyle commented 9 years ago

Why not have the shadow post type name always be under 16 chars, by using some abstraction function to hash the post type name in the case of it being longer than the max chars?

It seems even with this ticket, Babble still wouldn't support post type names at 16 chars.

simonwheatley commented 9 years ago

I've been resisting that as an idea, because I like the principle that the shadow post type names in the database for each post type remain human readable, as (in most cases) was the original default language post type name. I'd prefer to encourage developers to name their CPTs accordingly, but I guess they're not always going to have control if the CPT is added by a third party plugin, etc.

joehoyle commented 9 years ago

@simonwheatley worth mentioning - we'd only need to hash names that were longer than 14 chars (or whatever) so you'd only get an ugly name for the edge cases.

simonwheatley commented 9 years ago

See Core Trac #28303

simonwheatley commented 9 years ago

To add more context to the above core trac link :smile: the locale variants, e.g. Portuguese formal, adds a _formal suffix, more than doubling the length of the locale name. This clearly compounds our problem here :disappointed:

johnbillion commented 9 years ago

This is a pretty crappy situation. Like Simon, I'd love to retain the readability of post type names, but with a _de_DE_formal suffix, it only leaves seven characters for the actual post name.

Three options:

simonwheatley commented 9 years ago

@joehoyle @johnbillion My preference is:

simonwheatley commented 9 years ago

Note Dominik's reply in core trac:

There are official sub tags which are even longer than seven chars, for example 1694acad in fr-FR-1694acad. BCP47 includes a section about Length Considerations which says, that there is no upper limit for language tags but "buffer sizes for language tags MUST allow for language tags of at least 35 characters." So this sounds more like an implementation issues which needs to be fixed in the plugin, not something we have to consider if we want to support (official) variants of a languages.

simonwheatley commented 9 years ago

(doh, didn't mean to close… stupid buttons)

johnbillion commented 9 years ago

Purely so I can say "told-you-so" at some point in the future, a prediction: hashing shadow post type names will come back and bite us in the ass.

simonwheatley commented 9 years ago

Low blow, @johnbillion, low blow. Nobody disagrees, but what can we do? :worried:

markoheijnen commented 9 years ago

No special way at Automattic to get something fixed in WordPress 4.4 😉 Just kidding but we should have a list on what we need to be fixed in WordPress and this would be really high on that list. Unsure if there is an ticket for this but I believe they finally want to tackle option_name length.

simonwheatley commented 9 years ago

@markoheijnen @johnbillion @joehoyle Is there a consensus that we should only implement _doing_it_wrong at this point, and open a ticket to increase the length of the post_type field? 20 does seem short, at least in this context, but how long should it be? Bear in mind the length considerations Dominik pointed out, i.e. "buffer sizes for language tags MUST allow for language tags of at least 35 characters". 64 characters? 128?

markoheijnen commented 9 years ago

I guess 64 would be enough.

simonwheatley commented 9 years ago

Having considered this some more, I believe:

So…

simonwheatley commented 9 years ago

Closed in #301