Jump to content

Recommended Posts

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


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 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 ?
$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.

Share this post

Link to post
Share on other sites
  • 5 weeks later...

As far as I know the new translation system is not fully compliant with the legacy code (aka modules etc).
Somewhere I have read (message by company employee) that until further notice we should use the legacy translation system.

Share this post

Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More