在此服务器上找不到Zend Translate / locale / set / en

时间:2014-01-11 15:00:23

标签: php zend-framework localization zend-translate

我是zend框架的新手,我发现你第一次使用它时会遇到明显的问题。现在我正在设置翻译功能,并且,为了编写网站的语言,我放置了两个标志,一个用于网站的语言,另一个用英文标记。它应该以这种方式工作,我已经建立了一个特定的控制器:

 <?php

 class LocaleController extends Zend_Controller_Action
 {

     public function init()
     {
         // init code       
     }

     public function indexAction()
     {
    // action body
     }

     public function setAction()
     {
    // if supported locale, add to session
    if (Zend_Validate::is($this->getRequest()->getParam('locale'), 'InArray',
            array('haystack' => array('en', 'it'))))
    {
        $session = new Zend_Session_Namespace('ttb.l10n');
        $session->locale = $this->getRequest()->getParam('locale');
    }
    // redirect to requesting URL
    $url = $this->getRequest()->getServer('HTTP_REFERER');
    $this->_redirect($url);
     }


 }

在语言环境控制器中,我编写了“set”动作,它采用了“en”和“it”参数。 (我已经设置了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' => 1));
    $registry = Zend_Registry::getInstance();
    $registry->set('Zend_Translate', $translate);
}

然后在indexController.php文件中我有:

    public function init()
{
    /* Initialize action controller here */
    $registry = Zend_Registry::getInstance();
    $this->view->locale = $registry->get('Zend_Locale');
}

然后在layout.phtml中我有链接:

        <a href="/locale/set/it"><img src="<?php echo $this->baseUrl(); ?>/immagini/flag/italia.png" title="Italiano"></a>      
        <a href="/locale/set/en"><img src="<?php echo $this->baseUrl(); ?>/immagini/flag/inghilterra.png" title="English"></a>

我正在使用zend framework 1.12 ...

1 个答案:

答案 0 :(得分:0)

我只需将链接更改为以下内容:

        <a href="<?php echo $this->baseUrl(); ?>/locale/set/it"><img src="<?php echo $this->baseUrl(); ?>/immagini/flag/italia.png" title="Italiano"></a>      
        <a href="<?php echo $this->baseUrl(); ?>/locale/set/en"><img src="<?php echo $this->baseUrl(); ?>/immagini/flag/inghilterra.png" title="English"></a>