如何在gettext .po文件中指定有序变量? [英] How to specify ordered variables in gettext .po files?

查看:74
本文介绍了如何在gettext .po文件中指定有序变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多语言站点,该站点使用Zend_Translate PHP数组处理翻译.效果很好,但是我试图转换为使用gettext,因为它提供了额外的功能.

I have a multi-lingual site that uses Zend_Translate PHP arrays to handle the translations. It works fine, but I'm trying to convert to using gettext since that offers extra features.

但是,我还没有发现我喜欢在PHP数组翻译中使用的功能的gettext等效项: n $位置说明符(

However, I haven't yet discovered the gettext equivalent of a feature that I liked in PHP array translations: n$ position specifier (example #4 of PHP sprintf).

我找到了想要的好例子(请注意变量的顺序是中英文不同):

I found a good example of what I want (notice how the order of the variables is different in English and Chinese):

#: 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 文件具有以下内容:

But I haven't gotten it working for me. My en/messages.po file has this:

#, 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是这样的(它已用于翻译的数组样式,但我认为它不应该改变):

and the PHP is this (which had worked for the array style of translations, and I don't think it is supposed to change):

<?php echo $this->translate('Earn X cash', '<span class="earnCashBack">', '</span>', '<a href="/stores" class="numStores">', '</a>'); ?>

HTML出现错误,如下所示:

The HTML comes out wrong, like this:

$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文件?

How must I edit the .po file for this to work? Or should I not be using php-mo for compiling the .po into the .mo file?

推荐答案

在我尝试注释掉php-mo.php的这一行后,我的.po和.mo文件起作用了(并且我的网页看起来不错):

My .po and .mo files worked (and my webpage looks good) after I tried commenting out this line of php-mo.php:

$x = str_replace('$', '\\$', $x);

我实际上不确定为什么会出现该行,但是删除它会使我感到紧张,因为我可能正在引入尚未发现的错误.但是至少它解决了我可以看到的问题!

I'm actually not sure why that line was there at all, but removing it makes me nervous that I might be introducing bugs that I haven't discovered yet. But at least it fixed the problems that I could see!

这篇关于如何在gettext .po文件中指定有序变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆