带有消息'locale''的未捕获异常'Zend_Locale_Exception'不是已知的语言环境'

时间:2014-01-11 16:34:00

标签: zend-framework localization zend-translate zend-locale

我正在尝试在zend框架中翻译一个网站,但是,鉴于这是我第一次使用这个框架,我遇到了一些问题。最后一个是给出了你在这里作为标题看到的错误的那个。 我在Bootstrap文件中设置了两个重要的方法:

    protected function _initLocale()
{
 $session = new Zend_Session_Namespace('ttb.l10n');
 if ($session->locale) 
 {
    $locale = new Zend_Locale($session->locale);
 }
 if ($locale === null) 
 {
    try 
    {
        $locale = new Zend_Locale('browser');
    } 
    catch (Zend_Locale_Exception $e) 
    {
      $locale = new Zend_Locale('en');
    }
 }
 $registry = Zend_Registry::getInstance();
 $registry->set('Zend_Locale', $locale);
}

protected function _initTranslate()
{
    $translate = new Zend_Translate('array',
            APPLICATION_PATH . '/../languages/',
            'null',
            array('scan' => Zend_Translate::LOCALE_FILENAME,
                    'disableNotices' => 0));
    $registry = Zend_Registry::getInstance();
    $registry->set('Zend_Translate', $translate);
            return $translate;
}

问题在于,如果我想在我的页面中进行正确的翻译,我必须将语言环境设置为$ translate变量,并为我将向用户显示的每个视图设置它。该网站只有一个页面,所以我假设变量$ translate在每个动作中都是可用的,我更改了indexController.php的init方法:

     public function init()
{
    /* Initialize action controller here */
    $registry = Zend_Registry::getInstance();
    //The following is for the links that set the local language manually
    $this->view->locale = $this->_getParam('locale');
    if(!$this->view->locale){
        $this->view->locale = $registry->get('Zend_Locale');
    }
    $translate->setLocale($locale);
}

我得到的错误如下(来自zend服务器):

 Function Name  Zend_Application::bootstrap
 Error Type     E_ERROR
 Source File    /usr/local/zend/apache2/htdocs/project/public/index.php
 Error String   Uncaught exception 'Zend_Locale_Exception' with message 'The locale '' is no known locale'

如果有人可以提供帮助,我将不胜感激。 谢谢 SP

0 个答案:

没有答案