Zend的translate()函数问题
我正在使用 Zend Framework 构建多语言网站。翻译是通过 Zend_Translate_Adapter_Gettext 完成的。我正在使用 poedit 准备 .mo 文件。
问题是当我设置两个 msgid 并且其中一个的 msgstr 与另一个 msgid 相同时:
#: application/modules/foobar/views/scripts/index.phtml:1
msgid "foo"
msgstr "bar"
#: application/modules/foobar/views/scripts/index.phtml:2
msgid "bar"
msgstr "baz"
当我使用此代码时:
<?php echo $this->translate('foo'); ?>
<?php echo $this->translate('bar'); ?>
输出是这样的:
bazbaz
我认为如果 msgstr 与不同的 msgid 一致,则使用它就像msgid,因此被再次翻译。如果我的推理有误,请纠正我。
现在,我想知道您是否遇到过类似的问题以及如何轻松地规避它。
我当前的解决方案包括更改 msgids:
#: application/modules/foobar/views/scripts/index.phtml:1
msgid "KEY_FOO"
msgstr "bar"
#: application/modules/foobar/views/scripts/index.phtml:2
msgid "KEY_BAR"
msgstr "baz"
然后:
<?php echo $this->translate('KEY_FOO'); ?>
<?php echo $this->translate('KEY_BAZ'); ?>
这不是一个令人满意的解决方案,因为我正在开发一个包含约 10k 文件的社区门户,并且我无法真正检查所有文件是否存在冲突。
如果它有任何用处:
- Zend Framework 版本:1.10.8
- poedit 版本:1.4.6
- site running on Apache 2.2.11 with PHP 5.3
[编辑]
感谢 Gordon,我可以包含另一条数据:涉及 PHP 的 获取文本。我使用了完全相同的测试 .mo 文件,包括“foo”->“bar”和“bar”->“baz”键值对。 PHP 代码是这样的:
<?php
putenv('LC_ALL=pl_PL');
setlocale(LC_ALL, 'pl_PL');
bindtextdomain("pl", ".");
textdomain("pl");
echo gettext("foo");
echo gettext("bar");
?>
结果:
barbaz
所以这绝对不是 gettext
的错。
I'm using Zend Framework for a miltilingual site. Translating is done with Zend_Translate_Adapter_Gettext. I'm preparing the .mo files using poedit.
The problem is when I set up two msgids and one has a msgstr identical to the other msgid:
#: application/modules/foobar/views/scripts/index.phtml:1
msgid "foo"
msgstr "bar"
#: application/modules/foobar/views/scripts/index.phtml:2
msgid "bar"
msgstr "baz"
When I use this code:
<?php echo $this->translate('foo'); ?>
<?php echo $this->translate('bar'); ?>
the output is this:
bazbaz
I figure that if the msgstr coincides with a different msgid, it is used as if it was a msgid and thus is translated again. Please correct me if my reasoning is wrong.
Now, I'd like to know whether you've had a similar problem and how to circumvent it painlessly.
My current solution includes changing the msgids:
#: application/modules/foobar/views/scripts/index.phtml:1
msgid "KEY_FOO"
msgstr "bar"
#: application/modules/foobar/views/scripts/index.phtml:2
msgid "KEY_BAR"
msgstr "baz"
and then:
<?php echo $this->translate('KEY_FOO'); ?>
<?php echo $this->translate('KEY_BAZ'); ?>
This is not a satisfactory solution since I'm working on a community portal with ~10k files and I can't really check all of it for conflicts.
If it's of any use:
- Zend Framework version: 1.10.8
- poedit version: 1.4.6
- site runs on Apache 2.2.11 with PHP 5.3
[EDIT]
Thanks to Gordon, I can include another piece of data: a test involving PHP's gettext
. I used the very same test .mo file, including "foo"->"bar" and "bar"->"baz" key-value pairs. The PHP code was this:
<?php
putenv('LC_ALL=pl_PL');
setlocale(LC_ALL, 'pl_PL');
bindtextdomain("pl", ".");
textdomain("pl");
echo gettext("foo");
echo gettext("bar");
?>
And the result:
barbaz
So it's definitely not gettext
's fault.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
改变顺序
change the order