Search
Close this search box.

Documentation

In this article

Category:

Categories

Recent articles

Translation error sprintf printf too few arguments

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.

Join 700.000 users and install The Privacy Suite for WordPress locally, automated or fully customized, and access our awesome support if you need any help!

Complianz has received its Google CMP Certification to conform to requirements for publishers using Google advertising products.