PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, June 30, 2022

[FIXED] What is the correct domain for a new translation in a PrestaShop class override?

 June 30, 2022     module, overriding, prestashop, translation     No comments   

Issue

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:

  1. "Shop.Notifications.Error" (same as the other strings): and then looked in BO > Theme Translations > My Theme (or classic theme) > French (store language)

  2. "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.


Solution

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:

  1. Back office
  2. International -> Translations
  3. Modify translations
  4. Type of translation -> Installed modules translations
  5. Select your module -> modulename
  6. Select your language -> Language you want to translate

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.



Answered By - Crezzur
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing