In this blog, we will learn how to translate phrases in the override files. Sometimes we need to override the core PrestaShop classes and controllers and need to add some of our own phrases. But when we translate the module, these phrases are not available in the translation list because core files use the new translation system.
ie:
$this->errors[] = $this->trans( 'This voucher does not exist.', [], 'Shop.Notifications.Error' );
To overcome this issue, we need to create a class in our module, and in this class, we create a method and then create an instance of the module and use the old translation method and return it.
ie:
class WkTestTranslation { public static function getOverrideTransMsg() { $objModule = Module::getInstanceByName('wktestmodule'); return $objModule->l('This is custom error message.'); } }
To use the above method, we simply call the method in the module overridden file:
WkTestTranslation::getOverrideTransMsg();
Now, this phrase will be available under the module translation section in the back office:
That’s all.
If any issue or doubt in the above process, please feel free to let us know in the comment section.
I would be happy to help.
Also, you can explore our PrestaShop Development Services and a large range of quality PrestaShop Modules.
For any doubt contact us at [email protected].
Be the first to comment.