2009-09-30 44 views
0

我遇到了問題。基本上,根據用戶是否在我們的網站上轉到/ es或/ br或/ cn等,我們有不同的語言模板文件。到目前爲止,我們使用自定義模板引擎來完成這項工作,但正在切換到ZF。如果語言varuable是cn,我似乎無法弄清楚如何讓ZF在cn/about-us中查找視圖腳本。Zend Framework和切換視圖腳本路徑

我不能(不想)爲此使用Zend_Translate,因爲我們有太多的翻譯的模板文件,並且使用Zend_Translate爲bazillion中文/韓文/日文多段文本不同的文件是不可行的,忘記了一秒鐘,我不會說這些語言。

任何人都可以幫助我嗎?

回答

2

您可以編寫一個控制器插件並使用它的routeStartup()方法來更改Zend_View設置(視圖腳本所在的路徑)並在路由啓動之前更改請求uri。

class My_Controller_Plugin_LanguageSwitcher extends Zend_Controller_Plugin_Abstract 
{ 
    public function routeStartup(Zend_Controller_Request_Abstract $request) 
    { 
     // examine the $_SERVER['REQUEST_URI'] and look for your language identifier 
     // fetch the View and set appropriate view scripts path using setScriptPath() method 
     // strip the language identifier from your REQUEST_URI 
     // change the request uri using $request->setRequestUri('your-new-uri-without-the-language- identifier'); 
    } 
}