[英]Glib equivalent of `textdomain()` and `bindtextdomain()`
[英]zend framework 2 Set TextDomain in onBootstrap
我成功地遵循了此鏈接的說明,現在我的網站是多語言的,不需要在“ traslate()”調用中放入“語言環境”。 但是我每次調用時都必須放置TextDomain。
$this->traslate("Hello", __NAMESPACE__) //where __NAMESPACE__ is the text domain.
我想在onBootstrap方法中設置TextDomain,而不是將其放在“ traslate()”幫助程序的每次調用中。 我已經嘗試過使用setTextDomain方法,但是它不存在。 有人知道怎么做嗎?
onBootStrap代碼如下:
.....//Code for define $locale.
$sm = $e->getApplication()->getServiceManager();
$translator = $sm->get('translator');
$translator->setLocale($locale);
$traslator->SetTextDomain($textdomain); //This line not work!!!!!
第一次沒有看到這個。 通過DASPRIDS 演示有關ZF2 I18N的正確調用函數是:
$this->plugin('translate')->setTranslatorTextDomain('module-b');
盡管如果我正確地看到了這一點,那是從腳本視圖中進行的。 但是,從ServiceManager獲取翻譯器-我尚未對此進行測試-但請嘗試以下操作:
$translator->getPluginManager()->get('translate')->setTranslatorTextDomain('foo');
好。 我們前進了一步。
第一個解決方案可以正常工作(視圖解決方案),現在我的網頁僅使用此幫助程序參數來翻譯文本,這些參數是配置定義的Locale和TextDomain:
$ this-> translate('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.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.