我使用此代码来获取国家/地区名称,
Mage::getModel('directory/country')->loadByCode('DE')->getName();
在此示例中我得到“德国”。我怎样才能获得国家名称的翻译以显示例如德语的“Deutschland”?
注意:我不在前端模块中使用代码(它必须独立于客户的前端语言)。
非常感谢您的帮助。
最佳答案
当然,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
类作为替代:
$locale = new Zend_Locale('de_DE');
$countries = $locale->getTranslationList('Territory', $locale->getLanguage(), 2);
echo $countries['DE'];
关于Magento:获取指定语言的国家/地区名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13305612/