Jump to content

[Error/Bugs] New module translation system 1.7.6.x


Recommended Posts

Reference: https://devdocs.prestashop.com/1.7/modules/creation/module-translation/new-system/
PrestaShop version: 1.7.6.1
Debug mode: Active

Hello,

I've been monitoring this issues since PrestaShop 1.7 releases, so I was using the Classic translation system for my module until now.
PrestaShop 1.7.6.2 has been released and I still get a problem with New module translation system 1.7.6.x.

Here we go ...

My custom module name is `Ecmo` (ecmo.php) and it had two Admin controllers files: adminecmo.php and AdminEcmoTwo.php also had two Front controllers: sales.php and product.php
In my core module file ecmo.php I decide to use "translation domain naming scheme" : 'Modules.Ecmo.Core' and it working fine where the translations text appearing normally in Admin > International > Translations >> Modules >>> Ecmo : Core
and the translation text also working fine when displayed on Admin Installed modules.
e.g :

$this->displayName = $this->trans('Export CSV Master Order', array(), 'Modules.Ecmo.Core');

 

The problem begin when I'm starting to develop Admin Module Controller adminecmo.php which is extending AdminOrdersControllerCore >> class AdminEcmoController extends AdminOrdersControllerCore
When opening the Admin Module Page an error displayed:

Call to a member function trans() on null

That happen if I'm following  the new module translation system as stated on the references.
e.g: (this should work but it doesn't)

$this->trans('ID', array(),  'Modules.Ecmo.Adminecmo')

Next I was thinking that maybe it doesn't work because in this controller I was extending "AdminOrdersControllerCore" instead "ModuleAdminController", so I try another approach and still get an error (a different error)

Call to protected method ModuleCore::trans() from context 'AdminEcmoController'

That happen if I'm using this approach :

$this->module->trans('ID', array(),  'Modules.Ecmo.Adminecmo')

Note: $this->module has been defined on the __construct() method. $this->module = Module::getInstanceByName('ecmo');

Next I try another approach which is working but this approach doesn't following the standard coding as stated on the references.

 $this->context->getTranslator()->trans('ID', array(),  'Modules.Ecmo.Adminecmo')

Note: $this->context has been defined on the __construct() method. $this->context = Context::getContext();
 

Now let's continue with the other Admin controller on my module: AdminEcmoTwo.php which is extending ModuleAdminController >> class AdminEcmoTwoController extends ModuleAdminController
and the same problem happening so the same workaround also applied.

 

The Question: 
Is this a bugs or just an error on my module ?
Why 
$this->trans method doesn't work on my module Admin Controller ?
 

I didn't check the bugs tracker yet but already searching the similar topic on the forum but did not find an answer.
I didn't yet digging into the related core Prestashop to figuring out why this problem happening.
Also this discussion yet talking about the translation my module front controller.

Link to comment
Share on other sites

  • 5 weeks later...
  • 1 year later...

I'm not sure why almost nobody reply to this thread, even the Prestashop team.
Prestashop Doc. also doesn't mentioned about this issue and cannot found any clue at all on Prestashop bugs tracker https://devdocs.prestashop.com/1.7/modules/creation/module-translation/classic-system/

I just remember and back to this thread again because my client who still use PS 1.7.6.x had a translation problem with one of my module front controller file.
So here it is the work around of this problem :
For ModuleFrontController file the PHP code which should be use to make the translation work should be written like this :

$this->l('Text to translate', 'controller_filename');
// OR
$this->module->l('Text to translate', 'controller_filename');

Example
if your ModuleFrontController filename is default.php, then the PHP code for the translation text should be like this :

$this->l('Text to translate', 'default');
// OR
$this->module->l('Text to translate', 'default');

 

Link to comment
Share on other sites

Hello,

@gonebdg - webindoshop.com

I also using the same version. Unfortunately I was not able to deal with this problem.  

 

class VnreparationDeviceSelectionModuleFrontController extends ModuleFrontController

Page title translation does not work for my getTemplateVarPage() method inside class blocks.

Very strange. Translation variables are created in the back office. However, it is not triggered after language change in UI.

public function getTemplateVarPage()
    {
        $page = parent::getTemplateVarPage();

        $page['meta']['title'] = $this->trans('Device Selection', array(), 'Modules.Vnreparation.Device_selection');
        $page['meta']['description'] = '';
        $page['meta']['keywords'] = '';

        $page['headerColor'] = 'greenBg';

        return $page;
    }

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...