Next: Objective C Format Strings, Up: The Translator’s View [Contents][Index]
C format strings are described in POSIX (IEEE P1003.1 2001), section XSH 3 fprintf(), https://pubs.opengroup.org/onlinepubs/9799919799/functions/fprintf.html. See also the fprintf() manual page man fprintf.
Although format strings with positions that reorder arguments, such as
"Only %2$d bytes free on '%1$s'."
which is semantically equivalent to
"'%s' has only %d bytes free."
are a POSIX/XSI feature and not specified by ISO C 99, translators can rely
on this reordering ability: On the few platforms where printf()
,
fprintf()
etc. don’t support this feature natively, libintl.a
or libintl.so provides replacement functions, and GNU <libintl.h>
activates these replacement functions automatically.
C format strings can contain placeholders
that reference macros defined in ISO C 99 <inttypes.h>
.
For example, <PRId64>
references the macro PRId64
.
The value of such a macro is system-dependent,
but programmers and translators do not need to know this value.
ISO C 23 specifies system-independent format string elements,
for example, "%w64d"
instead of "%" PRId64
;
however, as of 2024, these are not implemented across systems
and therefore cannot be used portably.
As a special feature for Farsi (Persian) and maybe Arabic, translators can
insert an ‘I’ flag into numeric format directives. For example, the
translation of "%d"
can be "%Id"
. The effect of this flag,
on systems with GNU libc
, is that in the output, the ASCII digits are
replaced with the ‘outdigits’ defined in the LC_CTYPE
locale
category. On other systems, the gettext
function removes this flag,
so that it has no effect.
Note that the programmer should not put this flag into the untranslated string. (Putting the ‘I’ format directive flag into an msgid string would lead to undefined behaviour on platforms without glibc when NLS is disabled.)
Next: Objective C Format Strings, Up: The Translator’s View [Contents][Index]