0

TextDomain我跟着這個link的指示成功,現在我的網站是沒有在「平移,()」電話,要求放「區域」多語言。 但我必須把每次我稱之爲TextDomain。Zend框架2設置在onBootstrap

$this->traslate("Hello", __NAMESPACE__) //where __NAMESPACE__ is the text domain. 

我想設置TextDomain在onBootstrap方法,而不是把它放在了「平移,()」幫手的每次調用。 我已經嘗試過使用setTextDomain方法,但它不存在。 有人知道它是如何做到的?

的onBootStrap守則如下:

.....//Code for define $locale. 
    $sm = $e->getApplication()->getServiceManager(); 
    $translator = $sm->get('translator'); 
    $translator->setLocale($locale); 
    $traslator->SetTextDomain($textdomain); //This line not work!!!!! 
+0

這是複製和粘貼?因爲在這種情況下,它使某種意義上說,它不會工作OT)'$ traslator' =>'$ translator'和'SetTextDomain()'=>'setTextDomain()' – Sam

+0

喔對不起。這是一個寫入錯誤(不要複製和粘貼)。我也看過zend API文檔,這種方法不存在。 – josepmra

回答

0

Okey。我們已經邁出了一步。

第一個解決方案工作正常(視圖解決方案),現在我的網頁譖課文只使用這個輔助參數,被現場和TextDomain由配置定義:

$這個 - >翻譯(「HELLO」) ;

但第二個解決方案不工作。我不明白,因爲在視圖中接受相同的插件,而當名稱相同時,不在onBootstrap中。

我怒吼重寫我的onBootstrap代碼:

$translator = $e->getApplication()->getServiceManager()->get('translator'); 
    $pm = $translator->getPluginManager(); //until here works ok. 
    $pm->get('translate'); //this throws an error message how if 'translate' not found. 
1

沒有看到這在第一時間。通過DASPRIDS Presentation about ZF2 I18N走向正確的函數調用是:

$this->plugin('translate')->setTranslatorTextDomain('module-b'); 

雖然如果我正確地看到這一點,從視圖腳本里的。然而,從ServiceManager獲得翻譯器 - 我沒有測試過這個 - 但請嘗試以下操作:

$translator->getPluginManager()->get('translate')->setTranslatorTextDomain('foo');