Can you help me with the use of the "domain" parameter in $this->trans()
function ?
In my own module I have an override for the CartRule class. My override works correctly - it is copied from my module to the override folder by Presta and the code functions.
I have a new translated string inside, and I do not know what value to give for "domain".
My code:
$this->trans('Promotion codes cannot be combined', array(), 'Shop.Notifications.Error'); \\ ID, parameters, domain
For domain I have tried:
"Shop.Notifications.Error" (same as the other strings): and then looked in BO > Theme Translations > My Theme (or classic theme) > French (store language)
"Modules.[Mymodule].Admin" (for Mymodule I used a captialized short name): and then looked in BO > Module Translations > My Module > French (store language). This approach follows the PrestaShop rules.
Each time I have not found my string.
Do you have some ideas?
N.B. other answers on SO make use of $this->l
which is not available in this context.
I have also tried $this->module->trans()
but "module" is not available in this context.
First of all in your module we have to specify which strings are translatable.
Translating for Prestashop (version 1.7.5 and older):
TPL:
{l s='My text to translate' mod='modulename'}
PHP:
$this->module->l('My text to translate');
Translating for Prestashop (version 1.7.6 and newer):
TPL:
{l s='My text to translate' d='Modules.Modulename.Somefile'}
TWIG:
{{ 'My text to translate'|trans({}, 'Modules.Modulename.Admin') }}
PHP:
// For back-office translations we use "Admin"
$this->trans('My text to translate', array(), 'Modules.Modulename.Admin');
// For front-office translations we use "Shop"
$this->trans('My text to translate', array(), 'Modules.Modulename.Shop');
Ash you can see we need to declare its a translatable string from a Module, with the Modulename (with a capital), and then define where the translatable string is located Admin, shop
Important note Using the prestashop new translation system needs to be declared in your module. so in your main php file, mymodule.php add following code:
public function isUsingNewTranslationSystem()
{
return true;
}
PrestaShop Developer Documentation (translations)
Information about the Classic module translation system (1.7.5 and <) can be found here.
Information about the New module translation system (1.7.6 and >) can be found here.
Translating your module:
After defining all translatable strings we install our module to a Prestashop web-shop.
When our module is installed we have to go to:
This progress will generate a translation file (.php) in your module.
Translation file location: modulename/translations/isocode.php
Good to know is that when you have one translated PHP file of your module (example en.php) you can translate the same, en.php, file multiple times and save it under a different isocode for example nl.php.