dorzki Posted June 8, 2017 Share Posted June 8, 2017 Hello, I'm trying to add support for multiple languages. I have a function which runs when InvoicePaid hooks runs and sends an SMS notification to a certain phone number. I've created two language files under lang directory on my addon directory - hebrew and english. in English the file content is: <?php $_ADDONLANG['sms_message'] = 'Test'; But i can't seem to get the language in the function, i've tried $LANG and even Lang::trans('sms_message') and all i get is null. Would love to get help as the developer documentation sucks. 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted June 9, 2017 Share Posted June 9, 2017 you need to call the language file first: <?php add_hook("Your-Action-Hook-Point", 1, function($vars){ include ROOTDIR . "/modules/addons/{Your-Addon}/lang/english.php"; echo $_ADDONLANG['sms_message']; }); 0 Quote Link to comment Share on other sites More sharing options...
dorzki Posted June 9, 2017 Author Share Posted June 9, 2017 Why? How so i know which language the current user uses? Why WHMCS modules are so complicated, those are basic things that needs to be loaded automatically in the system... 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted June 9, 2017 Share Posted June 9, 2017 user language can be detected using a session variable: $userLang = $_SESSION['Language']; // or the following global $CONFIG; $userLang = $CONFIG['Language']; inside module functions the it's simple to use your translation <?php function addonmodule_output($vars){ $LANG = $vars['_lang']; echo $LANG['sms_message']; } 0 Quote Link to comment Share on other sites More sharing options...
Jumm Posted May 28, 2020 Share Posted May 28, 2020 What need to pass variable to lang? I have in english.php $_ADDONLANG['sms_message $variable']; How can I get it in the hook? 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted May 29, 2020 Share Posted May 29, 2020 9 hours ago, Jumm said: What need to pass variable to lang? I have in english.php $_ADDONLANG['sms_message $variable']; How can I get it in the hook? you would need to do it by adding a key in the translation phrase as: $_ADDONLANG['sms_message'] = "Hello :name"; then when you are about to display/use that phrase, you should replace that key with the appropriate value: function addonmodule_output($vars) { $_lang = $vars['_lang']; // an array of the currently loaded language variables from addon module $helloMessage = str_replace(":name", "John", $_lang['sms_message']); echo $helloMessage; // Hello John } that's how it works, and you can define as many different keys as you would need 0 Quote Link to comment Share on other sites More sharing options...
Jumm Posted May 29, 2020 Share Posted May 29, 2020 Thank you for answer whmcs functional doesn't have better option than php function str_replace? 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted May 29, 2020 Share Posted May 29, 2020 11 minutes ago, Jumm said: Thank you for answer whmcs functional doesn't have better option than php function str_replace? well, for WHMCS main language I would use the following: Lang::trans('sms_message', array('name' => "John")) and that support to work as they use Laravel! but as you want to use Addon language translation and as all the phrases has been already assigned into an array ($vars['_lang']) and since WHMCS doesn't have the same functionality above, the only option is to use "str_replace" which will give you the same result. 1 Quote Link to comment Share on other sites More sharing options...
Jumm Posted May 29, 2020 Share Posted May 29, 2020 Thank you 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.