How to validate positional notation placeholders in format strings with msgfmt?

226 Views Asked by At

When using printf-like format strings in a translated text msgfmt --check checks that the translation still contains the placeholders. For example, running xgettext on the following code

printf( gettext( "string: %s, int: %d" ), str, i )

produces a .po file with a msgid flagged as c-format and whose value is "string: %s, int: %d". If the translator forgets either %s or %d in the translation then msgfmt complains:

number of format specifications in 'msgid' and 'msgstr' does not match

Unfortunately this check does not apply to format strings using positional notation, like

boost::format( gettext( "string: %1%, int %2%" ) ) % str % i

How can I validate the presence of the positional notation placeholders in my translations?

1

There are 1 best solutions below

0
On

Not direct answer, but maybe following solution could solve your problem:

boost::format( gettext( "string: %1$s, int %2$d" ) ) % str % i;