theme-check
theme-check copied to clipboard
[Function _n] What wrong?
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?
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
.
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.
Looking at this check, a lot of this should probably be removed in favour of the WPCS I18n sniff which already handles this correctly.
But the sniff is a totally different context.
@joyously What do you mean ? Isn't the TRTCS sniffer supposed to be (or already) integrated in the Theme Check plugin ?
No, they are totally separate.
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).
I will make the time to take oversee the sniffer projects :)