Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#44340 new defect (bug)

Make use of sprintf function while translating strings

Reported by: saimonh Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9.6
Component: Users Keywords: has-patch close
Focuses: coding-standards Cc:


This is not a bug rather it's an improvement. In the wp-includes/user.php file, there are some <strong> tag has which has been used inside the translated () function.

So it's better to make use of sprintf function here than hard-coding the <strong> tag.

Screenshot: https://d.pr/free/i/qbHq2z


Attachments (1)

patch.diff (8.4 KB) - added by saimonh 3 years ago.

Download all attachments as: .zip

Change History (3)

3 years ago

#1 @abdullahramzan
3 years ago

  • Focuses coding-standards added

#2 @GaryJ
3 years ago

  • Keywords close added

Hi @saimonh,

Congrats on creating your first ticket :-)

In this case, I'd say that the change is unnecessary.

It's fine for strings to have basic HTML in them. In some cases, it's necessary, so that the translator can choose what word has the strong emphasis, or which words are the link text, etc.

In this case, you've split the strings up into multiple strings, which doesn't help with understanding context - they might be a different word for "ERROR", depending on what the issue is, but after your patch, that wouldn't be easy to adjust for, without also adding context (_x()) which then results in the same string having to be translated mutliple times.

Also, you've left the colon (:) in the sprintf template, meaning other punctuation can't be used if other locales use something different to a colon.

If markup is only at the ends of a string, then that's more likely to be a good candidate for pulling the markup out.

Note: See TracTickets for help on using tickets.