ChrisTERiS Posted March 6, 2020 Share Posted March 6, 2020 Hello, Is there any build-in function to get the active language to use it in a hook code? eg If is a visitor to return the site's default language, if it's a logon user to return the user's language. Thank you Chris 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 6, 2020 Share Posted March 6, 2020 Hi Chris, I thought you had retired - are you planning on making the greatest comeback since Lazarus ? 🙂 37 minutes ago, ChrisTERiS said: is there any build-in function to get the active language to use it in a hook code? eg If is a visitor to return the site's default language, if it's a logon user to return the user's language. possibly depends on the hook and what you have access to, but I would have thought that you could use $vars['language'] and return the current CA language value in lowercase... there's the ActiveLocale array too, but the language value in that should be the same as 'language'. 0 Quote Link to comment Share on other sites More sharing options...
ChrisTERiS Posted March 6, 2020 Author Share Posted March 6, 2020 (edited) @brian! I'm retired !!! 🙂 🙂 (but still waiting to get my pension on hands) But coding is like virus... can't stay inactive for long time. So from time to time I'm trying to add some extra features in my mods. Today I decided to make Legal Agreements multilingual. It got me just a couple of hours. Was really easy. But now I've to deal with the difficult (??) part. To know the active language, and show the correct articles. Maybe the $_SESSION keeps this data. I found a smarty variable $activeLocale that also holds the language, but this works only in tpl files, while I want to use it in my hook file. Happy to see you again here, active and helpful as always 🙂 Edited: $_SESSION["Language"] works at least in the place that I want. Have tried it before but didn't worked as I didn't noticed that is Language and not language 😞 Edited March 6, 2020 by ChrisTERiS Typo 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 6, 2020 Share Posted March 6, 2020 6 minutes ago, ChrisTERiS said: Today I decided to make Legal Agreements multilingual. It got me just a couple of hours. Was really easy. But now I've to deal with the difficult (??) part. To know the active language, and show the correct articles. how are you creating the multilingual text ? if you using addon language files, WHMCS should use the correct language file without any intervention... https://developers.whmcs.com/addon-modules/multi-language/ 17 minutes ago, ChrisTERiS said: Maybe the $_SESSION keeps this data. I could be wrong, but I think the language is only set in the session on a language change - though i'm probably thinking of CA hooks.... hopefully, if you're following the addon language method above, you might not need to work out the user's language. 0 Quote Link to comment Share on other sites More sharing options...
ChrisTERiS Posted March 6, 2020 Author Share Posted March 6, 2020 (edited) 1.- I added a field in agreements table to hold the language. Then I query the agreements according to the active language. 2.- Yes, it's true. The $_SESSION["Language"] is empty if the non logon visitor does not changes language from the menu. But this was easy. If it's empty I set in the query the default (site) language. // Query Database for Agreements if (empty($_SESSION["Language"])) { $ct_agreements = Capsule::table('mod_legalterms_articles') ->where('language','english') ->orderBy('displayorder','asc') ->get(); } else { $ct_agreements = Capsule::table('mod_legalterms_articles') ->where('language',''.$_SESSION["Language"].'') ->orderBy('displayorder','asc') ->get(); } The above code has hand-coded english as default language, but I'm in research to find the correct variable for it 🙂 Edited March 6, 2020 by ChrisTERiS 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.