WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#37789 closed defect (bug) (worksforme)

Strange results in comment number declension

Reported by: pavelevap Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: I18N Keywords:
Focuses: Cc:

Description

We have first bug report with the fix in #13651.

Function: comments_popup_link("Komentáře (0)", "Komentáře (1)", "Komentáře (%)");

Strange results:

0 – Komentáře (0)
1 – Komentáře (1)
3 – 3 komentáře
9 – 9 komentářů

Change History (5)

#1 @SergeyBiryukov
4 years ago

  • Keywords reporter-feedback added

Hi @pavelevap, thanks for the report!

What would be the expected results? As far as I can see, declension is working correctly for the last two strings (3 komentáře, 9 komentářů), the first two strings just need to be translated as 0 komentářů and 1 komentář.

#2 follow-up: @pavelevap
4 years ago

Thank you for creating new ticket :-)

It is not about translation. It is custom made theme with this function (without localization) and expected plural is Komentáře (%) without declension. Throughout the whole theme there should be only Komentáře (number) text, but there is default WP declension in effect (not wanted in this case).

It was also standard "hack" for previous bug and is commonly used now.

I can suggest our users for example gettext filter to change on to off, but maybe this could be fixed somehow directly (when original string in comments_popup_link() is not in English or without localization)?

#3 in reply to: ↑ 2 @SergeyBiryukov
4 years ago

Replying to pavelevap:

I can suggest our users for example gettext filter to change on to off, but maybe this could be fixed somehow directly (when original string in comments_popup_link() is not in English or without localization)?

Thanks for the clarification!

The problem is that get_comments_number_text() doesn't know if the string is in English or not, it just takes any text or markup passed as the $more argument and looks for the % character followed (or preceded) by a word.

So if declension is not needed in certain cases, gettext filter seems to be the appropriate way to disable it.

You could also use sprintf() to insert the number yourself, that way string would not contain the % character, and the supplied text will be used as is:

comments_popup_link(
	'Komentáře (0)',
	'Komentáře (1)',
	sprintf( 'Komentáře (%s)', number_format_i18n( get_comments_number() ) )
);
Version 0, edited 4 years ago by SergeyBiryukov (next)

#4 @SergeyBiryukov
4 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Closing, as the function works as expected, and there's a workaround to disable it for certain cases in comment:3.

Feel free to reopen if you think anything else should be done here.

#5 @pavelevap
4 years ago

Thank you, @SergeyBiryukov! I did not realize sprintf() hack to hide % :-)

Current solution is probably OK even if there are some edgecases. My only idea was to check if passed string is gettexted to prevent these situations, but I am not sure if it is possible somehow?

Note: See TracTickets for help on using tickets.