我有一个多语言站点,它使用 Zend_Translate PHP 数组来处理翻译。它工作正常,但我正在尝试转换为使用 gettext,因为它提供了额外的功能。
然而,我还没有发现 gettext 相当于我在 PHP 数组翻译中喜欢的功能:n$ 位置说明符 (PHP sprintf 的示例 #4 http://www.php.net/manual/en/function.sprintf.php).
我找到了一个好例子 http://codex.wordpress.org/Translating_WordPress#Examples_4我想要的(注意英语和中文中变量的顺序有何不同):
#: wp-admin/upload.php:96
#, php-format
msgid "File %1$s of type %2$s is not allowed."
msgstr "类型为%2$s的文件%1$s不允许被上传。"
但我还没有让它为我工作。我的en/messages.po文件有这个:
#, php-format
msgid "Earn X cash"
msgstr "%1$sEarn 1-30%% cash back%2$s, get money-saving coupons, and find the best price on every purchase at %3$s2,500+ stores%4$s."
PHP 是这样的(它适用于翻译的数组样式,我认为它不应该改变):
<?php echo $this->translate('Earn X cash', '<span class="earnCashBack">', '</span>', '<a href="/stores" class="numStores">', '</a>'); ?>
HTML 输出错误,如下所示:
$sEarn 1-30% cash back$s, get money-saving coupons, and find the best price on every purchase at $s2,500+ stores$s.
我必须如何编辑 .po 文件才能使其工作?或者我不应该使用php-mo https://raw.github.com/josscrowcroft/php.mo/master/php-mo.php将 .po 编译成 .mo 文件?