Eduardo G. Posted November 24, 2022 Share Posted November 24, 2022 Hi all. I have created several multi-language addons using "lang" folder inside the addon folder:https://developers.whmcs.com/addon-modules/multi-language/ And it's ok as long I use those translations from _output and _sidebar. But then my hooks cannot take that advantage. They just can't see _LANG variables Also method Lang::trans() is not valid because it doesnt take into account those custom addon's language files. Of course I cannot ask the customers to edit their global lang overrides, also that wouldn't be correct. So question is: how could I use custom addon own lang files and translation from inside this adddon's hook file? TIA. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted November 24, 2022 Share Posted November 24, 2022 (edited) There could be a better approach that I am not aware of but that's how I do it. When I started coding in WHMCS (2009) there were no Lang::trans() and autoloader so I had to find a way myself. In my module hooks.php file I require my autoloader (it can also be a normal php file) where the constructor perfoms various things including the loading of my language files depending on current user/visitor language. I also take into account overrides directory if present in modules/{MyModule}/lang/overrides. This way customers can override $_ADDONLANG like they already do for $_LANG. <?php require 'my_module_autoloader.php'; add_hook('AnnouncementAdd', 1, function($vars) { $hook = Hook::getInstance($vars); die($hook->addonlang->welcome_message); }); Over the years I used new(), singleton, and dependency injection approach. They all work. Edited November 24, 2022 by Kian 0 Quote Link to comment Share on other sites More sharing options...
Eduardo G. Posted November 25, 2022 Author Share Posted November 25, 2022 Thanks, Kian I've been working on that approach too, just didn't want to reinvent the wheel 😕 But it seems there's no other way. Well, I could fill a feature request xD xD 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.