2012-11-23 112 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