2013-01-09 50 views
0

在我的應用程序使用藪語言。 I'n我module.php我通過後續梅索德設置用戶的語言環境:ZF2 CurrencyFormat上默認的語言環境不工作

$translator = $e->getApplication()->getServiceManager()->get('translator'); 
$translator ->setLocale(\Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE'])) 
      ->setFallbackLocale($this->setDomainLocale()); 

有正在運行的服務器domain.tdl這個應用程序(不同的語言)的,所以我用一個函數在我的後備設置每個域,反正退區域...

我想利用currencyFormat的,但我沒有得到它的工作與用戶的語言環境中使用它。我試過下面的代碼,沒有'\ Locale :: getDefault())'; 像'1509053'這樣的數字,應該返回爲'€1.509.053.00'或','取決於語言環境,我只得到'€1509053.00'。

$this->plugin("currencyformat")->setCurrencyCode("EUR")->setLocale(\Locale::getDefault()); 

輸出\區域的:: getDefault())module.php $譯者

string(11) "en_US_POSIX" 

輸出

class Zend\I18n\Translator\Translator#193 (8) { protected $messages => array(0) { } 
protected $files => array(0) { } protected $patterns => array(1) { 'default' => array(1) { [0] => array(3) { 'type' => string(7) "gettext" 'baseDir' => string(119) "..../module/.../config/../language" 'pattern' => string(5) "%s.mo" } } } protected $remote => array(0) { } protected $locale => string(35) "nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4" protected $fallbackLocale => string(5) "nl_NL" protected $cache => NULL protected $pluginManager => NULL } 

希望有人可以把我在正確的方向:)日Thnx

+0

這只是一個假設,但該錯誤可能是設置了'Locale'內。它不應該是'en_US_POSIX',而應該是'en_US'。嘗試通過'acceptFromHttp' – Sam

+0

嗯..手動,而不是設置地方。如果我同時設置(HTTP |備用),以nl_NL默認輸出仍然是「en_US_POSIX」。當我在貨幣中設置nl_NL'hard' - > setLocale()時,它的工作原理如同 – directory

+0

好吧,我想我知道了。我想,通過設置翻譯語言環境,我們自動設置Locale :: getDefault()aswel。這似乎是不正確的,並且需要通過Locale :: setDefault()來設置此函數的語言環境aswel; – directory

回答

0

爲了使用功能 '\地點:: getDefault();'我們需要先設置'\ Locale :: setDefault(language_code);' $ translate-> setLocale不會設置Locale :: getDefault();.

+0

這是正確的。 $ translate-> setLocale()(或任何$ component-> setLocale())將始終爲該特定組件/實例設置固定的語言環境。 – DASPRiD

相關問題