2012-11-23 113 views
1

的正確調用其中的這些功能是否正確的方法在Magento調用助手:Magento的翻譯

Mage::helper('helper_class)->__('String to be translated); 

v

$this->__('String to be translated); 

回答

1

兩個!

這真的取決於你在哪裏調用它,你的翻譯位於何處。

讓我們來看看它們。首先這一個:

$this->__('String to be translated); 

如果它被稱爲助手類本身的內部它將返回這個輔助函數屬於模塊的轉換。否則,它將返回核心Magento翻譯。

Mage::helper('helper_class)->__('String to be translated); 

在所有其他情況下,此代碼必須用於獲取特定模塊的翻譯。

+0

良好的信息,一個小細節 - 塊(&模板)上下文中的'$ this'將使用塊的'module_name'屬性來調用,該屬性從類名派生 - 參見['Mage_Core_Block_Abstract :: __()'] (https://github.com/benmarks/magento-mirror/blob/1.7.0.2/app/code/core/Mage/Core/Block/Abstract.php#L1079)和[':: getModuleName()']( https://github.com/benmarks/magento-mirror/blob/1.7.0.2/app/code/core/Mage/Core/Block/Abstract.php#L1063) – benmarks