Next: No unusual markup, Previous: No embedded URLs, Up: Preparing Translatable Strings [Contents][Index]
The GNU C Library’s <printf.h>
facility and the C++ standard library’s <format>
header file make it possible for the programmer to define their own format string directives. However, such format directives cannot be used in translatable strings, for two reasons:
To avoid this situation, you need to move the formatting with the custom directive into a format string that does not get translated.
For example, assuming code that makes use of a %r
directive:
fprintf (stream, _("The contents is: %r"), data);
you would rewrite it to:
char *tmp; if (asprintf (&tmp, "%r", data) < 0) error (...); fprintf (stream, _("The contents is: %s"), tmp); free (tmp);
Similarly, in C++, assuming you have defined a custom formatter
for the type of data
, the code
cout << format (_("The contents is: {:#$#}"), data);
should be rewritten to:
string tmp = format ("{:#$#}", data); cout << format (_("The contents is: {}"), tmp);