WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 5 months ago

#40901 new defect (bug)

get_comments_number_text() third argument not used in certain situations

Reported by: eclare Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Comments Keywords: needs-patch needs-docs
Focuses: docs Cc:
PR Number:

Description

comments_number() is a wrapper for echoing get_comments_number_text().

Reference: https://codex.wordpress.org/Function_Reference/comments_number

The 3rd parameter's description: Text to display when there is more than one comment. % is replaced by the number of comments, so '% so far' is displayed as "5 so far" when there are five comments.

This doesn't seem to work as expected. In particular, the parser doesn't look just for '%' but also for strings with spaces in front or behind this sign, after which it processes it in a illogical way.

For example, this code

<? _e('Read on', 'anytextdomain');
comments_number(' and add the first comment', ' and see the first comment', ' % so far'); ?>
...

results in: Read on 2 komentarze... ("komentarze is a Polish translation of "comments", which is ok). Where's the "so far" string?

Now another example with text before the % sign:

<? _e('Read on', 'anytextdomain');
comments_number(' and add the first comment', ' and see the first comment', ' and view % comments'); ?>
...

The result is bizarre: Read on2 komentarze...

With some testing it seems that some strings passed as the 3rd argument are being kept, but it's totally illogical and requires review. If this is somehow intended, it should be explained in the Codex. So far, even the Codex example doesn't work as intended. I also checked that I'm not using any comments_num* filters.

Workaround: use get_comments_number() with conditional code.

Change History (1)

#1 @earnjam
5 months ago

  • Focuses docs added; template removed
  • Keywords needs-patch needs-docs added
  • Milestone changed from Awaiting Review to Future Release
  • Summary changed from get_comments_number_text() third argument parsing weirdly to get_comments_number_text() third argument not used in certain situations
  • Version 4.7.5 deleted

This is specific to the Polish translation (or other languages where the comment number translation requires declension).

In those cases, when the 3rd parameter contains a %, it is not used and it just uses a translation of % Comments. This should probably be clarified in the documentation.

Note: See TracTickets for help on using tickets.