我有一个使用 Zend_Translate PHP 数组来处理翻译的多语言站点。它工作正常,但我正在尝试转换为使用 gettext,因为它提供了额外的功能。
但是,我还没有发现我在 PHP 数组翻译中喜欢的功能的 gettext 等效项:n$ 位置说明符(PHP sprintf 的示例 #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将 .po 编译到 .mo 文件中?