Jump to content
Sign in to follow this  
zitu4life

How to custumize: Override languages names

Recommended Posts

Hello

How can we customize client area languages names to display two letters?

image.png.dd9d1e67bf5c98ad08a1a75459f2edbf.png

So we have image.png.edd1f3c3c581ac49fa29a316e7ce4063.png

And I am looking to have just EN like some wordpress websites display

image.png.89b4e6522f120087c2797646f1ee725e.png

WHMCS default languages overrides can not do that.

 

Share this post


Link to post
Share on other sites
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");

oWpPHsi.png

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.

Share this post


Link to post
Share on other sites
Posted (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.

image.png.81ed57f5e06d8aabb4e407cdbe05db42.png

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 by zitu4life

Share this post


Link to post
Share on other sites
Posted (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 by Kian

Share this post


Link to post
Share on other sites
Posted (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.

image.thumb.png.b3fb3a9ed5fdef9ac591a7c2c8f38861.png

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!

image.thumb.png.4423cd6ea58f688cae4ead047e4ee06f.png

Edited by zitu4life
replace above >>>to bellow

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Posted (edited)

Hi @brian!

Do you use same hook to made changes in print bellow or 2 hooks?

image.png.f4e029cc495826a66d5bdb372640b511.png

and you got this

image.png.275ea5f732ab34cde62a580888cd5e9f.png

while I got this image.png.a902197c72f686333b9afb4902fecc47.png

but on language selector it dit not use abreviations even on 21template

Edited by zitu4life

Share this post


Link to post
Share on other sites
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");

R99Fyy2.png

DeyA8AR.png

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.

Share this post


Link to post
Share on other sites
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...

image.png.a86e0ead981835ed711034f20a0dd6de.png

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.

Share this post


Link to post
Share on other sites
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....

SKhPHJ4.png

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.

1hLN04B.png

Share this post


Link to post
Share on other sites
Posted (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

image.png.ea22c98b6dade1ce22f2351c783ff7c2.png

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.

image.png.46738f22802692eb58bd8093cd1ab060.png

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...

image.png.8c8e3c11f9326efb8fefeb83e6ae2c59.png

So that is why I have to use BR language just for cosmetic, as BR is portuguese too.

 

 

Edited by zitu4life

Share this post


Link to post
Share on other sites
Posted (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 by Kian

Share this post


Link to post
Share on other sites
Posted (edited)

now I get it as desired even on desktop or mobile

image.png.7d9aa9ce6fee81d7323ad6ec5c37fb10.png

<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 by zitu4life
add>>> for not been editing a tpl file every time

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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. 🗒️

Share this post


Link to post
Share on other sites
Posted (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.

image.thumb.png.bb83801e1767ed54d8803bbf5a2c1e5c.png

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";

image.png.687d238d1e6eec466de106d8f30d8b58.png

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 

image.thumb.png.71986a5c83d069c2aad7385ee1350938.png

How can have PT>CV with flags images overrides too.

Edited by zitu4life

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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&nbsp;|&nbsp;$ 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

image.png.9f02c2939b96368ed8e986d4a8a4f870.png

 

image.png.705701d8b7150ff5a4234c4e17aac225.png

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

Share this post


Link to post
Share on other sites
if ($activelocale["language"] == "portuguese-pt") {
		$activelocale["localisedName"] = "CV";
		$activelocale["countryCode"] = "CV";

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated