Make WordPress Core

Opened 9 years ago

Last modified 2 months ago

#40901 new defect (bug)

get_comments_number_text() third argument not used in certain situations

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

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 (2)

#1 @earnjam
7 years ago

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

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.

This ticket was mentioned in ​PR #13268 on ​WordPress/wordpress-develop by ​skikken.


2 months ago
#2

  • Keywords has-patch has-unit-tests added; needs-patch removed

The patch narrows the heuristic to what the feature actually targets: the declined rewrite now only applies when the cleaned remainder is a single word (no internal whitespace). This keeps every existing single-word pattern working exactly as before (% Comments, <b>%</b> Replies, % <span class="reply">comments &rarr;</span>, and translated equivalents like % Komentarzy), while multi-word custom text falls through to the documented behavior: only the % character is substituted with the formatted number.

Trac ticket: https://core.trac.wordpress.org/ticket/40901

## Use of AI Tools
AI assistance: Yes
Tool(s): Claude
Model(s): Sonnet
Used for: test cases, code review

Note: See TracTickets for help on using tickets.