开发者

Zend_Translate, set up the log via the application resource plugin?

I'm using application resource plugins in a .ini file to set up my Zend_Translate with this code:

resources.translate.data = APPLICATION_PATH "/../languages"
resources.translate.adapter = "gettext" 
resources.translate.options.scan =  "directory"

Now I would like to add the log functionality to the translate, which in bootstrap I would do like thi开发者_开发知识库s:

$writer = new Zend_Log_Writer_Stream( APPLICATION_PATH . '/../logs/translate.log');
$log    = new Zend_Log($writer);
$translate->setOptions(
                array(
                    'log'             => $log,
                    'logUntranslated' => true
                )
            );

2 questions about this: First, is it possible to this in the .ini file?

Secondly, it is possible to "extend" resource settings in the bootstrap? In other words, could I add for example this log option in the bootstrap to the translate while maintaining the other settings already made in the .ini file?


Alright, I haven't found a solution to this in the ini file, but I have found a way to "extend" my settings from the ini file in the bootstrap without overwriting them. I managed to do that like this:

protected function _initTranslate()
{

    $writer = new Zend_Log_Writer_Stream( APPLICATION_PATH . '/../somedir/somefile.log');
    $log    = new Zend_Log($writer);

    // get the translate resource from the ini file and fire it up
    $resource = $this->getPluginResource('translate');
    $translate = $resource->getTranslate();

    // add the log to the translate
    $translate->setOptions(
            array(
                'log'             => $log,
                'logUntranslated' => true
            )
        );


    // return the translate to get it in the registry and so on
    return $translate;      

}

This works just fine. I'm going to remove the translate from the .ini though because I'm switching to my own adapter and don't know (yet) how to pull that off from the ini.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜