【发布时间】:2011-05-22 19:14:43
【问题描述】:
我正在将 Zend Framework 用于多语种网站。翻译是用 Zend_Translate_Adapter_Gettext 完成的。我正在使用 poedit 准备 .mo 文件。
问题是当我设置了两个 msgid 并且一个 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 并因此再次翻译。如果我的推理有误,请纠正我。
现在,我想知道您是否遇到过类似的问题,以及如何轻松绕过它。
我当前的解决方案包括更改 msgid:
#: 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 框架版本:1.10.8
- poedit 版本:1.4.6
- 网站在 Apache 2.2.11 和 PHP 5.3 上运行
[编辑]
感谢 Gordon,我可以包含另一条数据:涉及 PHP 的 gettext 的测试。我使用了相同的测试 .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的错。
【问题讨论】:
-
你能不能用 PHP 的
gettext做一个测试来排除这是正常的行为。 -
@Gordon,感谢您的评论,我将在一分钟内编辑我的帖子以包含 gettext 测试结果。
-
@mingos 你启用缓存了吗?当您将 bar/baz 对放在 po 文件中的 foo/bar 对之前时,是否也会发生这种情况。另外,当你在 translate('foo') 之前 translate('bar') 会发生什么?
-
@Gordon 和@mingos: Zend_Translate Gettext 适配器不是使用 PHP 的 gettext 扩展实现的(来源:Zend_Translate Adapter DOC:framework.zend.com/manual/en/zend.translate.adapter.html)
标签: php zend-framework internationalization poedit