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