• 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”)

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Chouby

    (@chouby)

    Hello,

    Thank you for the report. This looks like a conflict between Dynamo and WPML. We will look into it.

    Thread Starter ph1lm

    (@ph1lm)

    I have another site that uses en_GB lanaguage, so uses MO files, but NOT WPML. It does use Query Monitor.
    In output/html/overview.php line 374 I get the same sprintf() fatal error.
    The fix for cached values I used above does not work, I needed a similar fix for “\0” translations at line 137 to catch the non-cached translations.

    esc_html__( ‘%s S’, ‘query-monitor’ ) was returning BOTH singular AND pural translations which is WRONG (esc_html__ calls ->translate)

    Plugin Author Chouby

    (@chouby)

    Thank you for the second report.

    Meanwhile I was working on https://github.com/polylang/dynamo/pull/15 that I have just merged.

    Both issues are in fact the same. They are due to calls to __() with the same string as the singular form of a call to _n(). You can find that ‘%s S’ is also passed in a call to _n() in Query Monitor.

    According to my tests the PR #15 fixes both issues.

    If you have git and composer installed, you can build the current master branch available on https://github.com/polylang/dynamo to test it. It should fix your issues.

    Note that this development version also includes a new MO loader used when external object cache is available, but if you have none, this will use the same method as the current version 1.0.

    So if there is a fix, should this plugin be updated with this fix?

    @chouby is the fix going to be pushed ot the wp repo?

    Plugin Author Chouby

    (@chouby)

    This is now done with the version 1.1 just released.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘_n broken when DynaMo active but not when inactive’ is closed to new replies.