WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#20188 closed defect (bug) (fixed)

_n_noop() does not accept a textdomain

Reported by: scribu Owned by: nacin
Milestone: 3.4 Priority: normal
Severity: normal Version:
Component: I18N Keywords: has-patch
Focuses: Cc:

Description

A plugin tryng to use register_post_status() will have a hard time making the 'label_count' property translatable, since _n_noop() doesn't have a textdomain parameter, although translate_nooped_plural() does have it.

Previously: #13996

Attachments (1)

20188.diff (1.5 KB) - added by nacin 2 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 nacin2 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to maybelater
  • Status changed from new to closed
  • Type changed from defect (bug) to enhancement

It actually doesn't need it.

makepot does not use textdomains when scanning a file for strings. (It may in the future as an enhancement, to allow us to do things like move all multisite strings to their own pot, even if they exist in a regular core file.) The only job of _n_noop() is to get the string into the POT file. After that, translate_nooped_plural() is used to translate a string according to the textdomain.

We can consider this one an enhancement + maybelater, I think.

comment:2 johnbillion2 years ago

  • Resolution maybelater deleted
  • Status changed from closed to reopened
  • Type changed from enhancement to defect (bug)

This is in fact a bug.

Example: a plugin registers a post status and uses _n_noop() for its 'label_count' parameter, and its parameters are correctly added to the plugin's POT when it's scanned. However, when the label is output by WordPress using translated_nooped_plural() there's no textdomain parameter present, so gettext will try to translate the string according to core's textdomain rather than the plugin's.

I have a patch for this which I'll upload later when I'm back at my computer.

comment:3 SergeyBiryukov2 years ago

  • Milestone set to Awaiting Review

comment:4 nacin2 years ago

Not sure I am following. Example usage in a plugin:

$num_apples = 12;
$apple_string = _n_noop( 'Apple', 'Apples' );
translate_nooped_plural( $apple_string, $num_apples, 'my-plugin-textdomain' );

When makepot.php runs over this file, the strings 'Apple' and 'Apples' will be picked up and added to the plugin's POT.
When translate_nooped_plural() fires, it will call _n() internally with the domain passed to it.

comment:5 follow-up: scribu2 years ago

The trouble comes when translate_nooped_plural() isn't called by the plugin, but by Core. This happens with register_post_status(), as mentioned in the ticket description.

Last edited 2 years ago by scribu (previous) (diff)

comment:6 in reply to: ↑ 5 nacin2 years ago

  • Milestone changed from Awaiting Review to 3.4

Replying to scribu:

This happens with register_post_status(), as mentioned in the ticket description.

Kind of. I would have had to look up exactly how core translates 'label_count', as that's just about all that's mentioned. That's okay, though — I get it now.

Okay, so, let's fix it.

nacin2 years ago

comment:7 nacin2 years ago

  • Keywords has-patch added

Patch doesn't touch docs, just the code. Allows a domain to be specified, in which case it will override whatever is passed to translate_nooped_plural().

comment:8 nacin2 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from reopened to closed

In [20648]:

Allow nooped plurals to receive a textdomain on registration to then be used on translation.

This is good for when the code registering the plural is not also translating it. This occurs
in core with register_post_status(), which accepts a nooped plural as an argument, and then
calls translate_nooped_plural() without a domain.

translate_nooped_plural() can still be called with a domain. The argument will just be overridden
if the nooped plural contains a domain key.

fixes #20188.

Note: See TracTickets for help on using tickets.