_n broken when DynaMo active but not when inactive
-
I have a site using PHP 8, WordPress 5.8.3, WooCommerce 6.0.0, WPML 4.5,1, WPML String Translation 3.2.0.
When adding a product to the cart (“basket”) function wc_add_to_cart_message() calls _n() to return single/plural string.
wc_add_to_cart_message() then calls sprint() to insert the number into the string.
BUT since _n() has returned BOTH single AND plural strings, there are TWO % signs (one in each string!) and PHP detects that sprintf() should have 3 parameters including the string plus one for each placeholder and generates an ERROR instead of showing the page.wp-content\plugins\wpml-string-translation\classes\MO\Plural.php has filter ngettext which ends up calling __() on the original string which returns BOTH single and plural strings as one string which is WRONG
Turns out that src\mo.php translate() was finding the string “<singular>\0<plural>” and returning that.
If I add code to check for “\0” in the cached string and if found explode the string and run the plural forms handler for 1 and return the relevant item it returns just the singlar string as expected
(copied code from translate_plural “if cache key”… and used 1 instead of “$count”)
- The topic ‘_n broken when DynaMo active but not when inactive’ is closed to new replies.