[wp-trac] [WordPress Trac] #46946: Site Health: Text adjustment (add a link and remove "we")
WordPress Trac
noreply at wordpress.org
Thu Jun 20 14:10:00 UTC 2019
#46946: Site Health: Text adjustment (add a link and remove "we")
------------------------------------------------+---------------------
Reporter: birgire | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 5.3
Component: Text Changes | Version: 5.2
Severity: normal | Resolution:
Keywords: site-health has-patch dev-feedback | Focuses:
------------------------------------------------+---------------------
Comment (by leogermani):
So basically we have 3 options on how to localize a string with a HTML
link in it and Im going to summarize them here in this comment to make it
easier to get feedback on which is the best.
**Option 1**, basic
{{{
printf( __('Here is my <a href="%s">link to the admin</a>'), admin_url()
); `
}}}
**Option 2**, get HTML out of the translatable string
{{{
printf( __('Here is my %1$slink to the admin%2$s'), '<a href="' .
admin_url() . '">', '</a>' );
}}}
**Option 3**, As suggested in the codex with extra security precautions
(https://codex.wordpress.org/I18n_for_WordPress_Developers#HTML)
{{{
printf(
wp_kses(
__('Here is my <a href="%s">link to admin</a>'),
['a' => ['href' => [] ] ]
),
esc_url( admin_url( 'site-health.php' ) ) );
)
}}}
In my opinion, option 3 looks good. Less chance that the HTML gets broken
during the translation and, in simple cases such as this example, we could
use only `%s` instead of `%1$s`, which would make it even simpler.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/46946#comment:17>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list