Using the translate method

It was important for you to know what is available in the Context object. We will now see some useful methods and how to use them in our module.

The first one is the l method. This method is used to translate text. It will permit us to make our module multilingual:

$this->l('text I want to translate');

Note

As you can see, it takes the sentence you want to translate as a parameter. The method encodes the sentence in MD5, and then it searches whether a translation exists using MD5 as a key. If a translation is found, it returns it; otherwise, it returns the sentence passed in the parameter.

PrestaShop's best practice is to write the sentences in English in the source code.

In our case, we have to translate the displayName

Get PrestaShop Module Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.