The Privacy Suite for WordPress

Translation error sprintf printf too few arguments

Get compliant today in the European Union, United States, Canada, United Kingdom, Australia, Brazil & South Africa with the only Privacy Suite for WordPress that offers a fully-featured plugin for Worldwide Compliance.

This error might appear in strings with dynamic fields. The dynamic fields are designated with a ‘%s’, in the below example. These fields are then filled by variables, called $type. Both the dynamic fields and variables should have the same count:

( sprintf( __( "The cookie scan detected %s on your site, which means the answer to this question should be %s.", 'complianz-gdpr' ), $type, $type ) );

In this line of code, you will find a text-domain ‘complianz-gdpr’, which means it can be translated by our open-source community. Sometimes, a translator might overlook or forget to copy/paste the %s in the new language string causing an error. For example:

// Error as first %s misses a '%'
( sprintf( __( "The cookie scan detected s on your site, which means the answer to this question should be %s.", 'complianz-gdpr' ), $type, $type ) );

The above line would cause a fatal error, as the two $type variables can’t populate the dynamic fields. To mitigate this issue we have wrapped our translatable strings with a function, whereby we check the variable/field count. If the count is not correct, we default to %s as plain text and throw a warning to double-check the strings, with the above examples.

Recent articles

The Privacy Suite for WordPress
Get compliant today with the only Privacy Suite made for WordPress

Categories

Popular articles

Join our mailing list - 8 Tips & Tricks in your inbox over the next 8 weeks!