重写控制器时避免翻译丢失

重写控制器时避免翻译丢失

本文介绍了Magento:重写控制器时避免翻译丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这样重写控制器:

<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)

I overwrite only one function. Another function of the controller (left original) calls $this->__('A string'); when I track this down in the debugger, to Mage_Core_Controller_Front_Action::__() the translation expression ($expr) is

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

并且找不到翻译-因为仅在Mage_Checkout中可用.

and the translation is not found - because it is only available in Mage_Checkout.

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

I think the best solution would be to avoid controller rewrites and use events, but this is not possible in all cases.

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

Is there any clean solution - other than using events - to keep the original translation inside overwritten controllers?

推荐答案

解决方案非常简单.只需指定控制器名称中应使用的模块名称即可翻译字符串.

The solution is very simple. Just specify module name that should be used in controller to translate strings.

  • 为该类的$ _realModuleName属性指定值.

示例:

class My_Foo_SomeController extends Mage_Checkout_SomeController
{

    protected $_realModuleName = 'Mage_Checkout';

    // Some your code goes here
}

在这种情况下,Magento将使用此属性中的值来检索模块翻译,而不是尝试从类名中检测模块名称.

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

这篇关于Magento:重写控制器时避免翻译丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 06:28