Jump to content

How to translate strings in a front controller?


Recommended Posts

Hi all,

I've done a module "class MyModSubModSubModuleFrontController extends ModuleFrontController."

that works well.

 

In this module I'd like to translate strings so I've used this synstax: $this->l('Translate me');

 

But I've this error:

Call to undefined method MyModSubModSubModuleFrontController::l() in /var/www/vhosts/..../controllers/front/modsub.php on line 47
 

Which is the correct way to translate strings in a controller?

 

Thank you

 

Claudio

Link to comment
Share on other sites

Hello,

 

Try this:

 

require_once(dirname(__FILE__).'/mymodule.php');

$module = new MyModule();

$mytext = $module->l('Here is my text', 'mymodule');

 

Thank you for your advice, starting from that I've done this:

 

    private function translateString($mystring)

    {

        $mod_name = 'MyMod';

        $mod = Module::getInstanceByName($mod_name);

        return $mod->l($mystring, $mod_name);

    }

 

now using translateString, it works well.

 

Thank you

 

cld

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