Im curious, how you would implement this?
if I call the following in some preexisting application: printf( gettext("Please move %s."), gettext("king") );
the order of operations is : gettext("king"); gettext("Please move %s."); printf( %s , %s );
So how would the first gettext("king") know what to return?
One way would be to return all strings in some "intricate" ways. Eg, if we have
one=gettext("king"); // this should "somehow" (see below) provide all available strings
format=gettext("Please move %s");
and the printf(format,one) call would resolve to:
gettext_printf("Please move %<2>s", one);It might prove tricky to do preprocessor redefinitions of printf, so maybe addition of "gettext_" to all formatter functions could be a better solution, which would require programmers to replace all such calls.
Of course, one could define a new function named gettext_*printf which would work equivalently as *printf, just consider the string arguments as multi-string-containers, if the format instructs it to (contains "%<i>s"). Yes, I see now that it wouldn't be truly painless for programmers :-(
The particularly cumbersome would be initialization of strings with gettext-ed forms. It could be solved by using some kind of pointers (void*), but not very safe in that regard [if there are no special formatters in the format string, gettext_printf could resolve just back to printf call].
Another way could be using some magic number at the start of the string, and using the next machine-pointer-size bytes for locating a structure which holds all the values provided by gettext (yes, quite an ugly hack). This is also not failsafe.
The third ugly hack that crosses my mind now is to keep the default translation (the one with the <0> code, or without code), and put the pointer to extra data behind the string '\0' byte.
I think you could get this to work if there was some sort of context, which could be used to tie the whole thing together. such as:
void *ctx = gettext_context("Please move piece."); printf( gettext(ctx,"Please move %s."), gettext(ctx,"king") );
The default for context could be NULL, in which case there is no special behavior, but in cases where exceptional handling is required you could provide override strings. Context would have to be a mandatory part of each gettext call...
It's another way which would require much program redesign, so I'd try to avoid it. Of course, it would be much saner and cleaner than any of the many hacks described above.
Though, I admit I haven't invested much thought into it yet, but I posted it just as a generic proposal, and to see for how many languages would it be good for (from the translators' POV).
Cheers, Danilo
-- Linux-UTF8: i18n of Linux on all levels Archive: http://mail.nl.linux.org/linux-utf8/
