2012-11-09 40 views
2

我用這個代碼來獲得國名獲得國家名稱,Magento的:在指定的語言

Mage::getModel('directory/country')->loadByCode('DE')->getName(); 
這個示例中,我獲得「德國」的

。如何獲取國家/地區名稱的翻譯,例如在德語中顯示德語?

注意:我不使用frontendend模塊中的代碼(它必須獨立於客戶的前端語言)。

非常感謝您的幫助。

回答

4

當然Magento的翻譯引擎,可在外部腳本中使用:

Mage::getSingleton('core/translate')->init('de_DE', true); 
$country_name = Mage::getModel('directory/country')->loadByCode('DE')->getName(); 
echo Mage::helper('core')->__($country_name); 

或者你可以使用Zend_Locale類AR一種替代方案:

$locale = new Zend_Locale('de_DE'); 
$countries = $locale->getTranslationList('Territory', $locale->getLanguage(), 2); 
echo $countries['DE']; 
+0

是;)這樣的作品,非常感謝幫幫我 :) – Bizboss