[Gforge-devel] Switched to gettext

Roland Mas lolando at debian.org
Tue Mar 13 17:01:18 EDT 2007


Roland Mas, 2007-03-13 21:26:20 +0100 :

>   Hi all,
[...]

Oops.  I forgot to mention something fairly important: strings with
parameters.  They now use standard printf formats.  So strings with
one parameter are implemented with something like that:

printf(_("Hi, my name is %s, glad to meet you."), $name);

  In case of multiple parameters, it still works:

printf(_("My name is %s and I'm %d years old."), $name, $age);

  It becomes slightly trickier when you want to reorder parameters or
reuse some of them twice:

printf(_("I'm %2$d years old, and my name is %1$s.  Hello %1$s!",
       $name, $age);

  The simple style will work in most cases, at least in English; the
translators can use the complex style later on if needed.  For
instance, Japanese people use the "lastname firstname" order, contrary
to most Western cultures; but there's no problem with having the code
contain printf(_("My name is %s %s"), $firstname, $lastname) while the
ja.po file has something like "Blah blah %2$s %1$s" for the
translation of that string.

  Of course, if you need to get the result of the string rather than
print it out, you can use $result=sprintf(_("Translated string with
parameter %s"), $param).

Roland.
-- 
Roland Mas

Sauvez les castors, tuez les bûcherons.


More information about the Gforge-devel mailing list