theme-check icon indicating copy to clipboard operation
theme-check copied to clipboard

[Function _n] What wrong?

Open ghost opened this issue 8 years ago • 8 comments

This code of Woocommerce Plugin:

echo apply_filters( 'woocommerce_available_download_count', '<span class="woocommerce-Count count">' . sprintf( _n( '%s download remaining', '%s downloads remaining', $download['downloads_remaining'], 'domain' ), $download['downloads_remaining'] ) . '</span> ', $download );

but Them check is warning:

WARNING: Found a translation function that has an incorrect number of arguments. Function _n, with the arguments '%s download remaining', '%s downloads remaining', downloads_remaining, 'domain'

I see code here:

https://developer.wordpress.org/reference/functions/_n/

And my text domain is domain:

Warning: More than one text-domain is being used in this theme. This means the theme will not be compatible with WordPress.org language packs. The domains found are domain, downloads_remaining

I only found downloads_remaining in echo apply_filters( 'woocommerce_available_download_count', '<span class="woocommerce-Count count">' . sprintf( _n( '%s download remaining', '%s downloads remaining', $download['downloads_remaining'], 'domain' ), $download['downloads_remaining'] ) . '</span> ', $download );

What wrong?

ghost avatar Aug 03 '16 02:08 ghost

At the first glance I can't see an issue with with code with _n.

As for the text domain. The text domain must the same as the theme name. So if the theme is called. Olympic Champion then the text domain would be olympic-champion.

grappler avatar Aug 03 '16 05:08 grappler

The check itself is not perfect. It's seeing the string in $download['downloads_remaining'] and counting that as a possible argument which it is not expecting.

There's nothing wrong with your code. If you want to avoid the false error as a workaround for now, use a temporary variable to hold $download['downloads_remaining'] and use that in the _n call instead.

Otto42 avatar Aug 04 '16 20:08 Otto42

Looking at this check, a lot of this should probably be removed in favour of the WPCS I18n sniff which already handles this correctly.

jrfnl avatar Jun 05 '20 06:06 jrfnl

But the sniff is a totally different context.

joyously avatar Jun 05 '20 14:06 joyously

@joyously What do you mean ? Isn't the TRTCS sniffer supposed to be (or already) integrated in the Theme Check plugin ?

jrfnl avatar Jun 05 '20 15:06 jrfnl

No, they are totally separate.

joyously avatar Jun 05 '20 16:06 joyously

Nope, we're pausing the sniffer development because I just don't have the time to work on it (especially since it'S something I'm doing it on my free time).

dingo-d avatar Jun 06 '20 10:06 dingo-d

I will make the time to take oversee the sniffer projects :)

pattonwebz avatar Jun 06 '20 10:06 pattonwebz