note 25243 added to function.sprintf
| From: | no dot email dot address at example dot com | Date: | Mon, 16 Sep 2002 11:29:36 +0000 |
| Subject: | note 25243 added to function.sprintf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-36740@lists.php.net to get a copy of this message | ||
Using argument swapping in sprintf() with gettext: Let's say you've written the following
script:
<?php
$var = sprintf(gettext("The %2\$s contains %1\$d monkeys"), 2, "cage");
?>
Now you run xgettext in order to generate a .po file. The .po file will then look like this:
#: file.php:9
#, ycp-format
msgid "The %2\\$s contains %1\\$d monkeys"
msgstr ""
Notice how an extra backslash has been added by xgettext.
Once you've translated the string, you must remove all backslashes from the ID string as well
as the translation, so the po file will look like this:
#: file.php:9
#, ycp-format
msgid "The %2$s contains %1$d monkeys"
msgstr "Der er %1$d aber i %2$s"
Now run msgfmt to generate the .mo file, restart Apache to remove the gettext cache if necessary,
and you're off.
--
http://www.php.net/manual/en/function.sprintf.php
http://master.php.net/manage/user-notes.php?action=edit+25243
http://master.php.net/manage/user-notes.php?action=delete+25243
http://master.php.net/manage/user-notes.php?action=reject+25243