zitu4life Posted April 28, 2021 Share Posted April 28, 2021 Hello How can we customize client area languages names to display two letters? So we have And I am looking to have just EN like some wordpress websites display WHMCS default languages overrides can not do that. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 28, 2021 Share Posted April 28, 2021 10 hours ago, zitu4life said: How can we customize client area languages names to display two letters? let me guess.. you want to do it using a hook - even though it would be a one-line change in the template. 🙂 the quick way... <?php # Language Abbreviations Hook # Written by brian! function locales_hook($vars) { $mylocal = $vars['locales']; $activelocale = $vars['activeLocale']; foreach ($mylocal as $key => $value) { if ($mylocal[$key]["localisedName"] == "english") { $mylocal[$key]["localisedName"] = "EN"; } else { $mylocal[$key]["localisedName"] = strtoupper($mylocal[$key]["countryCode"]); } } if ($activelocale["language"] == "english") { $activelocale["localisedName"] = "EN"; } else { $activelocale["localisedName"] = strtoupper($activelocale["countryCode"]); } return array("locales" => $mylocal, "activeLocale" => $activelocale); } add_hook("ClientAreaPage", 1, "locales_hook"); in practice, there are visible errors with this - but they're primarily caused by bugs in WHMCS - namely AR for Arabic and TW for Chinese.... but WHMCS are aware of this.... they could be fixed in the hook, or via the above thread - however for you, @zitu4life where you only have 3 languages (English, Brazilian & Portuguese) enabled, the above hook should suit your needs. 1 Quote Link to comment Share on other sites More sharing options...
zitu4life Posted April 28, 2021 Author Share Posted April 28, 2021 (edited) 43 minutes ago, brian! said: et me guess.. you want to do it using a hook - even though it would be a one-line change in the template. 🙂 the quick way... Hi @brian! Many thanks. These abbreviations will help me save space on header, but it failed on my custom theme, my client error prompt an error. Whoops\Exception\ErrorException: Cannot redeclare locales_hook() (previously declared in /home/FAKEdatabaseNAME/public_html/includes/hooks/Specify Valid Languages for Language Chooser Hook.php:6) in /home/FAKEdatabaseNAME/public_html/includes/hooks/Language_Abbreviations_Hook.php:6 Stack trace: #0 /home/FAKdatabaseNAME/public_html/vendor/whmcs/whmcs-foundation/lib/Utility/Error/Run.php(0): WHMCS\Utility\Error\Run->handleError(64, 'Cannot redeclar...', '/FAKEdatabaseNAME/FAKEdatabaseNAME/...', 6) #1 [internal function]: WHMCS\Utility\Error\Run->handleShutdown() #2 {main} I guess this hook is not compatible with my custom module, if it is the case I can open a ticket with developer and ask them to try to make it work with some adjustment. Edited April 28, 2021 by zitu4life 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted April 28, 2021 Share Posted April 28, 2021 (edited) It's just a naming collision. Rename locales_hook with something else like in the following example. <?php # Language Abbreviations Hook # Written by brian! function brianIsSexy($vars) { $mylocal = $vars['locales']; $activelocale = $vars['activeLocale']; foreach ($mylocal as $key => $value) { if ($mylocal[$key]["localisedName"] == "english") { $mylocal[$key]["localisedName"] = "EN"; } else { $mylocal[$key]["localisedName"] = strtoupper($mylocal[$key]["countryCode"]); } } if ($activelocale["language"] == "english") { $activelocale["localisedName"] = "EN"; } else { $activelocale["localisedName"] = strtoupper($activelocale["countryCode"]); } return array("locales" => $mylocal, "activeLocale" => $activelocale); } add_hook("ClientAreaPage", 1, "brianIsSexy"); Or use the "short syntax". <?php # Language Abbreviations Hook # Written by brian! add_hook('ClientAreaPage', 1, function($vars) { $mylocal = $vars['locales']; $activelocale = $vars['activeLocale']; foreach ($mylocal as $key => $value) { if ($mylocal[$key]["localisedName"] == "english") { $mylocal[$key]["localisedName"] = "EN"; } else { $mylocal[$key]["localisedName"] = strtoupper($mylocal[$key]["countryCode"]); } } if ($activelocale["language"] == "english") { $activelocale["localisedName"] = "EN"; } else { $activelocale["localisedName"] = strtoupper($activelocale["countryCode"]); } return array("locales" => $mylocal, "activeLocale" => $activelocale); }); Edited April 28, 2021 by Kian 1 Quote Link to comment Share on other sites More sharing options...
zitu4life Posted April 28, 2021 Author Share Posted April 28, 2021 (edited) 1 hour ago, Kian said: It's just a naming collision. Rename locales_hook with something else like in the following example. Thanks Kian. it works, I modified to something else. These days I realized that WHMCS allows do a lot of things in customization. Actually I used only 2 Languages, EN and PT...BR is just cosmetic... what if want to display those two languages PT and EN side by side like picture below. a Hook can be modified to display that? I realized that usually hooks works even on custom templates, so if it can be done on blend perhaps it works on custom templates. @brian! Edited April 28, 2021 by zitu4life replace above >>>to bellow 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 29, 2021 Share Posted April 29, 2021 20 hours ago, zitu4life said: I guess this hook is not compatible with my custom module, if it is the case I can open a ticket with developer and ask them to try to make it work with some adjustment. no it was just me being lazy and modifying an existing hook - as Kian says, just renaming or anonymising the function would work.... however, if you have another hook of mine active that is modifying the same array, you might need to disable or merge it with this hook to avoid conflicting changes. i've got a horrible feeling i've posted many locales hooks with that same function name, so off-hand I don't know what your clashing hook is doing. 20 hours ago, Kian said: function brianIsSexy($vars) { easy there Tiger - people will talk! 👨❤️👨😎 20 hours ago, zitu4life said: These days I realized that WHMCS allows do a lot of things in customization. it always did - the trick is keeping a note of those customisations so that no clashes/conflicts occur! 20 hours ago, zitu4life said: Actually I used only 2 Languages, EN and PT...BR is just cosmetic... what if want to display those two languages PT and EN side by side like picture below. a Hook can be modified to display that? I suppose a JS hook could modify the content of that <li> - it's one of those things that not technically difficult to do, but awkward as it depends on the underlying content of the code in the template (it contains both language and currency).... i'm assuming there is a header.tpl in Croster that contains the li lang-btn class. 20 hours ago, zitu4life said: I realized that usually hooks works even on custom templates, so if it can be done on blend perhaps it works on custom templates. Blend is an admin template. the choice of template is not the issue, it's a case of either overwriting what's there, or modifying what's there to work in a slightly different way... ... and with custom templates, I don't necessarily know what that content is - e.g I don't have a copy of Croster locally to see. 0 Quote Link to comment Share on other sites More sharing options...
zitu4life Posted April 30, 2021 Author Share Posted April 30, 2021 (edited) Hi @brian! Do you use same hook to made changes in print bellow or 2 hooks? and you got this while I got this but on language selector it dit not use abreviations even on 21template Edited April 30, 2021 by zitu4life 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 30, 2021 Share Posted April 30, 2021 1 hour ago, zitu4life said: Do you use same hook to made changes in print bellow or 2 hooks? oh that's what the other hook did - it's removing unwanted languages... the problem here is that you'll have two separate hooks trying to manipulate the same array. so the first hook is basically from the thread below? if you were to combine them, you would get... <?php # Specify Valid Languages for Language Chooser Hook # Written by brian! function valid_languages_hook($vars) { $mylocal = $vars['locales']; $activelocale = $vars['activeLocale']; $validlanguages = array("english","french","dutch"); foreach ($mylocal as $key => $value) { if (!in_array($value["language"],$validlanguages)) { unset($mylocal[$key]); } elseif ($mylocal[$key]["language"] == "english") { $mylocal[$key]["localisedName"] = "EN"; } else { $mylocal[$key]["localisedName"] = strtoupper($mylocal[$key]["countryCode"]); } } if ($activelocale["language"] == "english") { $activelocale["localisedName"] = "EN"; } else { $activelocale["localisedName"] = strtoupper($activelocale["countryCode"]); } return array("locales" => $mylocal, "activeLocale" => $activelocale); } add_hook("ClientAreaPage", 1, "valid_languages_hook"); now don't make a third hook and post the above code into that - disable/remove the other two and only use this one. 🙂 1 hour ago, zitu4life said: while I got this I would guess that Croster is taking the activelocale value, but that's only a guess. 1 hour ago, zitu4life said: but on language selector it dit not use abreviations even on 21template try the updated hook and see if that makes any difference. 1 Quote Link to comment Share on other sites More sharing options...
zitu4life Posted April 30, 2021 Author Share Posted April 30, 2021 20 minutes ago, brian! said: I would guess that Croster is taking the activelocale value, but that's only a guess. it works on my dev installation, but not on my production... I will contact Croster development and see if they can look at it. @brian! Does that language box selector can be resized? I guess in past I contact my theme developer and says me something like it is a bootstrap column and its designed for all languages 🙄... because that box has 3 colons, and if i use only 2 languages, would be better if that box shows 2 columns for 2 languages...and it makes it better responsive on mobile phone. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 30, 2021 Share Posted April 30, 2021 32 minutes ago, zitu4life said: it works on my dev installation, but not on my production... are there any obvious differences between the two? e.g is there a hook running on the prod but not on the dev ? 38 minutes ago, zitu4life said: Does that language box selector can be resized? I guess in past I contact my theme developer and says me something like it is a bootstrap column and its designed for all languages 🙄... the modal window itself could be resized using CSS in a custom.css file.... 41 minutes ago, zitu4life said: because that box has 3 colons, and if i use only 2 languages, would be better if that box shows 2 columns for 2 languages...and it makes it better responsive on mobile phone. the three columns is defined in the footer.tpl template - that's just a case of changing the two col-4 used to col-6. 1 Quote Link to comment Share on other sites More sharing options...
zitu4life Posted April 30, 2021 Author Share Posted April 30, 2021 (edited) 25 minutes ago, brian! said: are there any obvious differences between the two? e.g is there a hook running on the prod but not on the dev ? probably it was a conflict hook... your last hook works now on my productions. I deactivate one of then and did not realized before, that I need only to change a language 3 hours ago, brian! said: $validlanguages = array("english","french","dutch"); to $validlanguages = array("english","portuguese-pt","portuguese-br"); So now I am using just one hook But like I sad before, on desktop it appears like picture above.. But on cellphone it appears... maybe my mobile phone screen is small, but do not think so. If I ever changed your hook to use just 2 languages $validlanguages = array("english","portuguese-pt"); <?php # Specify Valid Languages for Language Chooser Hook # Written by brian! function valid_languages_hook($vars) { $mylocal = $vars['locales']; $activelocale = $vars['activeLocale']; $validlanguages = array("english","portuguese-pt"); foreach ($mylocal as $key => $value) { if (!in_array($value["language"],$validlanguages)) { unset($mylocal[$key]); } elseif ($mylocal[$key]["language"] == "english") { $mylocal[$key]["localisedName"] = "EN"; } else { $mylocal[$key]["localisedName"] = strtoupper($mylocal[$key]["countryCode"]); } } if ($activelocale["language"] == "english") { $activelocale["localisedName"] = "EN"; } else { $activelocale["localisedName"] = strtoupper($activelocale["countryCode"]); } return array("locales" => $mylocal, "activeLocale" => $activelocale); } add_hook("ClientAreaPage", 1, "valid_languages_hook"); it displays wrong... So that is why I have to use BR language just for cosmetic, as BR is portuguese too. Edited April 30, 2021 by zitu4life 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted April 30, 2021 Share Posted April 30, 2021 (edited) You should be tuning viewport (the col-sm, col-md, col-lh, col-xl attributes). Croster probably uses col-sm (≥576px) so you should replace: col-{SOMETHING} col-sm-{SOMETHINGELSE} With this: col-6 col-sm-6 Edited April 30, 2021 by Kian 1 Quote Link to comment Share on other sites More sharing options...
zitu4life Posted April 30, 2021 Author Share Posted April 30, 2021 (edited) now I get it as desired even on desktop or mobile <input type="hidden" name="language" value=""> {foreach $locales as $locale} <div class="col-6 col-sm-6"> <div class="col-6 col-sm-6"> <a href="#" class="item{if $activeCurrency.id == $selectCurrency.id} active{/if}" data-value="{$selectCurrency.id}"> {$selectCurrency.prefix} {$selectCurrency.code} Thanks @brian! and @Kian Bad thing is that i have to edit footer.tpl on every update, but I will request a croster developer a solutions for future release, for not been editing a tpl file every time Edited April 30, 2021 by zitu4life add>>> for not been editing a tpl file every time 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted April 30, 2021 Share Posted April 30, 2021 2 hours ago, zitu4life said: Bad thing is that i have to edit footer.tpl on every update, but I will request a croster developer a solutions for future release, for not been editing a tpl file every time You could use two not very stylish workarounds. Override the entire class="" attribute with jQuery (onLoad) so that it always has the right col and col-sm For this specific div override the default col-4 width of Bootstrap so that it's 50% instead of 33.33% via CSS. You chould use !important or a longer selector (longer selector "beats" shorter one) 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 1, 2021 Share Posted May 1, 2021 16 hours ago, zitu4life said: Bad thing is that i have to edit footer.tpl on every update true, but even if you wrote a hook or used CSS to do it, there's no guarantee that it would still work in v8.2 anyway, so you're no worse off! 😎 the point being that an update of WHMCS could invalidate anything - hook, css or template change.. so always be aware of what you have changed and how a WHMCS update might impact that. 🗒️ 0 Quote Link to comment Share on other sites More sharing options...
zitu4life Posted May 23, 2021 Author Share Posted May 23, 2021 (edited) Hi @brian! Can you give a hand. I have tried to modify your hook trying "trial and error" but could not completed alone and sometimes it gets website broke. I have this hook: <?php # Specify Valid Languages for Language Chooser Hook # Written by brian! function valid_languages_hook($vars) { $mylocal = $vars['locales']; $activelocale = $vars['activeLocale']; $validlanguages = array("english","portuguese-pt"); foreach ($mylocal as $key => $value) { if (!in_array($value["language"],$validlanguages)) { unset($mylocal[$key]); } elseif ($mylocal[$key]["language"] == "english") { $mylocal[$key]["localisedName"] = "EN"; } else { $mylocal[$key]["localisedName"] = strtoupper($mylocal[$key]["countryCode"]); } } if ($activelocale["language"] == "english") { $activelocale["localisedName"] = "EN"; } else { $activelocale["localisedName"] = strtoupper($activelocale["countryCode"]); } return array("locales" => $mylocal, "activeLocale" => $activelocale); } add_hook("ClientAreaPage", 1, "valid_languages_hook"); and I want to overrides abbreviation PT to CV and also override flag image from PT to CV, I see that on WHMCS admin there is a CV flag somewhere. I am aware that modifications can be done possible here replacing english to portuguese-pt and so EN to PT If I just replace english>portuguese-pt and PT>CV I will get that EN will be changed automatically to GB abbreviation } elseif ($mylocal[$key]["language"] == "english") { $mylocal[$key]["localisedName"] = "CV"; } else { $mylocal[$key]["localisedName"] = strtoupper($mylocal[$key]["countryCode"]); } } if ($activelocale["language"] == "english") { $activelocale["localisedName"] = "CV"; Regarding flags image it self I even do not know how to override it. I found an image on WHMCS but it do not helps a lot How can have PT>CV with flags images overrides too. Edited May 23, 2021 by zitu4life 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 23, 2021 Share Posted May 23, 2021 52 minutes ago, zitu4life said: How can have PT>CV with flags images overrides too. if you're overriding PT to CV, then that's just a case of the hook returning a CountryCode value for the flag, and a localisedName value for the abbreviation - both will be CV. if you were going EN->CV, then that might require a nasty hack - but I don't think you want that. 0 Quote Link to comment Share on other sites More sharing options...
zitu4life Posted May 23, 2021 Author Share Posted May 23, 2021 2 hours ago, brian! said: if you're overriding PT to CV, then that's just a case of the hook returning a CountryCode value for the flag, and a localisedName value for the abbreviation - both will be CV. Thank you Brian, but what I guess what I am looking for is simple, it is just a cosmetic change...lets see... CV official language is also Portuguese, so my needs is just to instead of appears PT I need it to display CV. I have reached that modifying a hook to be like this. <?php # Specify Valid Languages for Language Chooser Hook # Written by brian! function valid_languages_hook($vars) { $mylocal = $vars['locales']; $activelocale = $vars['activeLocale']; $validlanguages = array("english","portuguese-pt"); foreach ($mylocal as $key => $value) { if (!in_array($value["language"],$validlanguages)) { unset($mylocal[$key]); } elseif ($mylocal[$key]["language"] == "portuguese-pt") { $mylocal[$key]["localisedName"] = "CV"; } else { $mylocal[$key]["localisedName"] = strtoupper($mylocal[$key]["countryCode"]); } } if ($activelocale["language"] == "portuguese-pt") { $activelocale["localisedName"] = "CV"; } else { $activelocale["localisedName"] = strtoupper($activelocale["countryCode"]); } return array("locales" => $mylocal, "activeLocale" => $activelocale); } add_hook("ClientAreaPage", 1, "valid_languages_hook"); So it works, but It can not display CV flag instead of PT flag. I inspected it on browser and I noted that flags are related to a code <button type="button" class="btn" data-toggle="modal" data-target="#modalChooseLanguage"> <div class="d-inline-block align-middle"> <div class="iti-flag cv"></div> </div> CV | $ CVE </button> <div class="d-inline-block align-middle"> <div class="iti-flag pt"></div> </div> So I have tried to change line <div class="iti-flag cv"></div> </div> where iti-flag pt to become iti-flag cv Also I changed it here <a href="#" class="item active" data-value="portuguese-pt"> <span class="iti-flag cv"></span> <span>CV</span> </a> replacing again iti-flag pt to become iti-flag cv But if I update browser I will loose changes, so it is just a cosmetic changes. Sorry if could been able to explain with other post 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 23, 2021 Share Posted May 23, 2021 if ($activelocale["language"] == "portuguese-pt") { $activelocale["localisedName"] = "CV"; $activelocale["countryCode"] = "CV"; 1 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.