[wp-trac] [WordPress Trac] #50493: more detailed notice for register_rest_route

WordPress Trac noreply at wordpress.org
Sun Jul 19 20:35:43 UTC 2020


#50493: more detailed notice for register_rest_route
--------------------------+-----------------------------
 Reporter:  Lwangaman     |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Future Release
Component:  REST API      |     Version:  5.4.2
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:  rest-api
--------------------------+-----------------------------

Comment (by TimothyBlynJacobs):

 > The reasoning behind the numbering order of the variables was the fact
 that logically, namespaces precede routes. So I ordered the sprintf
 variables logically: you will always find the namespace first and the
 route second. However in the error message itself, depending on the
 wording, sometimes the route might be mentioned before the namespace.

 In every error message the route is mentioned before the namespace. I
 agree its more logical for the namespace to come first when both are
 necessary. So why don't we order the error message that way?

 > That's the whole reason for using numbered variables: you can change the
 order in the sentence any which way without having to change the order of
 the variables as they are passed in.

 Right, but that's primarily used in WordPress so that translators can
 safely reorder variables.

 > So I would really prefer not to change that order, I believe it is more
 clear to leave the logical ordering namespace->route for the order of the
 variables as they are passed in.

 More logical for who? Translators aren't seeing the order of the function
 arguments, just the original string. I think for them it'll be more
 confusing for the order to be mismatched.

 In functions where translations and sprintf placeholders are used, the
 order doesn't always match the function signature. For instance,
 `map_meta_cap` or `rest_handle_deprecated_function`.

 Throughout the codebase I could only find one example of the `%2$s`
 placeholder preceding the first `%1$s` in the original string, and that is
 in a [https://github.com/WordPress/wordpress-
 develop/blob/b39df4606a882cba1a70b6debfedac44585d35b2/tests/phpunit/tests/db.php#L1528
 test case and isn't translated].

 I searched for the pattern `%2\$s.+%1\$s` which wouldn't catch everything,
 but it seems clear to me that by far the dominant pattern in WordPress is
 for the parameters to match the order of the English string.

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


More information about the wp-trac mailing list