ilclaudio Posted September 30, 2016 Share Posted September 30, 2016 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 More sharing options...
Logical IT Posted September 30, 2016 Share Posted September 30, 2016 Hello, Try this: require_once(dirname(__FILE__).'/mymodule.php');$module = new MyModule();$mytext = $module->l('Here is my text', 'mymodule'); 1 Link to comment Share on other sites More sharing options...
ilclaudio Posted September 30, 2016 Author Share Posted September 30, 2016 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 More sharing options...
Logical IT Posted September 30, 2016 Share Posted September 30, 2016 excellent, you're welcome. Link to comment Share on other sites More sharing options...
roja45 Posted September 30, 2016 Share Posted September 30, 2016 the module object is already available in the controller, just do $this->module->l(<YOUR STRING>) 2 Link to comment Share on other sites More sharing options...
ilclaudio Posted October 7, 2016 Author Share Posted October 7, 2016 Yes in fact in another product I've found this method: public function _l($string) { return $this->getModule()->l($string, __class__); } Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now