[wp-trac] [WordPress Trac] #46305: Update emails w/ placeholders to use sprintf
WordPress Trac
noreply at wordpress.org
Fri Feb 22 06:25:18 UTC 2019
#46305: Update emails w/ placeholders to use sprintf
-----------------------------+-------------------------------
Reporter: garrett-eclipse | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: I18N | Version:
Severity: normal | Resolution:
Keywords: | Focuses: coding-standards
-----------------------------+-------------------------------
Comment (by garrett-eclipse):
Thanks @dd32
Correct me if I'm wrong but the approach I was thinking with sprintf
should preserve the placeholders for the following filters and
str_replace's that occur after the email_date/email_text string is
created.
For example this string;
https://github.com/WordPress/WordPress/blob/c204ac4bc7972c9ca1e6b354ec8fb0851e255bc5
/wp-includes/functions.php#L6473-L6486
Can be converted to sprintf as follows;
{{{#!php
<?php
$email_text = sprintf(
/* translators: 1: ###SITENAME###, 2: ###USER_EMAIL###, 3:
###DESCRIPTION###, 4: ###MANAGE_URL###, 5: ###SITEURL### */
__(
'Howdy,
A user data privacy request has been confirmed on%1$s:
User: %2$s
Request: %3$s
You can view and manage these data privacy requests here:
%4$s
Regards,
All at %1$s
%5$s'
),
'###SITENAME###',
'###USER_EMAIL###',
'###DESCRIPTION###',
'###MANAGE_URL###',
'###SITEURL###'
);
}}}
This should leave the placeholders available in the string for filters,
etc. While improving the translator experience as GlotPress already has a
warning for placeholders missing;
`Warning: Missing %1$s placeholder in translation.`
That being said I understand the onus on rewriting these functions as the
systems emails and others have followed this same convention. Irregardless
if these emails change it would be a good call to implement a custom rule
so I opened a #meta to prompt use of the `gp_warning_placeholders_re`
filter to introduce a custom check on `###[A-Z_]+###`.
Meta Ticket - https://meta.trac.wordpress.org/ticket/4196
--
Ticket URL: <https://core.trac.wordpress.org/ticket/46305#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list