Magento: Avoid loss of translations when rewriting controllers

时间秒杀一切 提交于 2019-12-08 08:08:03

问题


I rewrite a controller like this:

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

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'

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?


回答1:


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

  • Specify value for $_realModuleName property of the class.

Example:

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.



来源:https://stackoverflow.com/questions/11882584/magento-avoid-loss-of-translations-when-rewriting-controllers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!