如何在 zend 中添加多种类型的翻译
我用了这个代码 尝试从 /resources/linguals 添加翻译数组 和 从 /application/languages/nl.mo (gettext) 添加翻译
$translate = new Zend_Translate(
array(
'adapter' => 'array',
'content' => APPLICATION_PATH . '/resources/languages',
'locale' => 'nl',
'scan' => Zend_Translate::LOCALE_DIRECTORY
)
);
$translate->addTranslation(
array(
'adapter' => 'gettext',
'content' => APPLICATION_PATH.DIRECTORY_SEPARATOR.'languages'.DIRECTORY_SEPARATOR.'nl_NL.mo',
'locale' => 'nl'
)
);
当我尝试添加单个翻译时,一切正常(在两种情况下) 当我添加第二个翻译时,出现此错误:
致命错误:未捕获的异常 'Zend_Translate_Exception' 与 消息'错误包括数组或文件 '1'' 中 blabla.php 第 61 行
有人可以告诉我如何从引导程序添加这些翻译文件,而不会出现这些错误吗?
I used this code
to try and add a translation array from /resources/languages
ANd
to add a translation from /application/languages/nl.mo (gettext)
$translate = new Zend_Translate(
array(
'adapter' => 'array',
'content' => APPLICATION_PATH . '/resources/languages',
'locale' => 'nl',
'scan' => Zend_Translate::LOCALE_DIRECTORY
)
);
$translate->addTranslation(
array(
'adapter' => 'gettext',
'content' => APPLICATION_PATH.DIRECTORY_SEPARATOR.'languages'.DIRECTORY_SEPARATOR.'nl_NL.mo',
'locale' => 'nl'
)
);
When i try to add a single translation everything works ok (in both cases)
When i'm adding a second translation i get this error:
Fatal error: Uncaught exception
'Zend_Translate_Exception' with
message 'Error including array or file
'1'' in
blabla.php
on line 61
can someone tell me how to add those translation files from my bootstrap, without getting these errors?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是 100% 确定,但我认为你不能混合类型的翻译文件。原因是
$translate->addTranslation()
实际上会调用Zend_Translate_Adapter_Array
上的方法addTranslation()
,而该方法又会调用一个方法_loadTranslationData
也在Zend_Translate_Adapter_Array
上。因此,Zend_Translate_Adapter_Array
尝试将文件nl_NL.mo
作为数组读取,这会导致包含数组或文件的错误错误。但是,如果翻译文件“nl”是来自 zend 资源的文件,并且您只想使用它来翻译 zend_form 消息,我认为您可以为此定义一个单独的转换器,如下所示:
并且您可以将“nl_NL”其余默认:
PS
我还没有测试过这个,因此我不能承认它有效,但这就是我至少会尝试这样做的方式。
I'm not 100% sure, but I think you cannot mix types of translation files. The reason is that
$translate->addTranslation()
will actually call a methodaddTranslation()
onZend_Translate_Adapter_Array
, which in turn will call a method_loadTranslationData
also onZend_Translate_Adapter_Array
. ThusZend_Translate_Adapter_Array
tries to read filenl_NL.mo
as an array which results in Error including array or file error.However, if the translation file 'nl' is the one from zend resources, and you want to use it only for translating zend_form messages, I think you could define a separate translator for this as follows:
And the 'nl_NL' you can make your default for the rest:
P.S.
I have not tested this, hence I cannot grantee it works, but this is how I would at least try to do it.