In this blog, we are going to learn how to use new translation system in PrestaShop module and translate the sentences and texts available in module.
Firstly while developing module we have to declare that we are going to use new translation system in module. For doing you need to add below code in module main class,
public function isUsingNewTranslationSystem() { return true; }
This indicates that you are going to use new translation system in module. Now you need to declare every sentences and text according to new translation system in PrestaShop module.
Secondly, for any text or sentences written in module main class, classes and admin controller you can use translation function as below
// For php files $this->trans('Unable to delete customer using id.', [], 'Modules.Modulename.Admin')); // For tpls {l s='My alerts' d='Modules.Modulename.Admin'} // For twigs {{ 'Follow up 1'|trans({}, 'Modules.Modulename.Admin', locale) }}
Here Admin denotes that this text is for admin domain.
Thirdly, for any text or sentences written in tpl, twig or front controller you can use translation function as below,
// For tpls {l s='My alerts' d='Modules.Modulename.Shop'} // For twigs {{ 'Follow up 1'|trans({}, 'Modules.Modulename.Shop', locale) }} // For php files $breadcrumb['links'][] = [ 'title' => $this->trans('My alerts', [], 'Modules.Modulename.Shop'), ];
Here Shop denotes that this text is for shop domain. You can put any domain in the place of Admin and Shop according to your use case to identify the text/sentence. This text will shown under module translation under there respective domain.
This is how we can use new translation system in PrestaShop module.
If you want to translate phrases in the overriden files follow the Translate phrases in overridden files in PrestaShop or if you want Translate newly added phrases in overridden files in PrestaShop.
That’s all.
If you are facing any issues or doubts in the above process, please feel free to contact us through 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].
Supported Framework Version - PrestaShop 1.7.7.x - 8.x.x
Be the first to comment.