Category: "Internationalization"

Preparing Translatable Strings

I am currently considering using GNU gettext utilities to internationalize b2evolution.

I'm not done reading the docs, but right now I just felt like I needed to work this out:

The gettext manual has this totally valid understanding about preparing translatable string:

Hardcoded string concatenation is sometimes used to construct English strings:

strcpy (s, "Replace ");
strcat (s, object1);
strcat (s, " with ");
strcat (s, object2);
strcat (s, "?");

In order to present to the translator only entire sentences, and also because in some languages the translator might want to swap the order of object1 and object2, it is necessary to change this ...

This sounds very wise... but the "solution" leaves me baffled:

...change this to use a format string:

sprintf (s, "Replace %s with %s?", object1, object2);

Okay... how exactly am I supposed to swap the order of the objects? Swap %s with %s... ? yeah, right... :crazy:

(For those of you familiar with C but not with translation, rememenber that the translator can only act upon the string "Replace %s with %s?", not upon the sprintf statement.)

Update: Doh! Just learnt something kewl about printf syntax! :. Solution is easy:

sprintf (s, "Replace %1$s with %2$s?", object1, object2);

And there's no reason to specify those order numbers until you need to change the order... well, actually there is a reason: give a hint to the translator who "may not" be a printf syntax expert... :!: