1

我像这样重写一个控制器:

<frontend>
    <routers>
       <checkout>
       <args>
     <modules>
       <My_Foo before="Mage_Checkout">My_Foo</My_Foo>
     </modules>
       </args>
       </checkout>
    </routers>

我只覆盖一个函数。$this->__('A string');当我在调试器中跟踪它时,控制器(左原始)调用的另一个函数到Mage_Core_Controller_Front_Action::__()翻译表达式($expr)是

_text = 'A string',
_module = 'My_Foo'

并且找不到翻译 - 因为它仅在Mage_Checkout.

我认为最好的解决方案是避免控制器重写和使用事件,但这并非在所有情况下都是可能的。

是否有任何干净的解决方案 - 除了使用事件 - 将原始翻译保留在覆盖的控制器中?

4

1 回答 1

8

解决方案非常简单。只需指定应该在控制器中用于翻译字符串的模块名称。

  • 为类的 $_realModuleName 属性指定值。

例子:

class My_Foo_SomeController extends Mage_Checkout_SomeController 
{

    protected $_realModuleName = 'Mage_Checkout';

    // Some your code goes here
}

In this case Magento will use value from this property to retrieve module translations instead of trying to detect module name from class name.

于 2012-08-09T13:17:48.940 回答