This hook allows to automatically switch WHMCS language, according to the default language set in the user's browser.

So, i.e., a user with a browser set in Deutch will have his WHMCS interface accordingly set in Deutch, a user with a browser set in Italian will have his WHMCS interface set in Italian, and so on...

(ref: https://whmcs.community/topic/264853-auto-switch-language-based-on-browser-language/ )

 

<?php

add_hook('ClientAreaPage', 10, switch_languagebrowser($vars));

function switch_languagebrowser($vars) {

$country_to_language = array(
'default' => 'english',
'AR' => 'arabic',
'AR-DZ' => 'arabic',
'AR-BH' => 'arabic',
'AR-EG' => 'arabic',
'AR-IQ' => 'arabic',
'AR-JO' => 'arabic',
'AR-KW' => 'arabic',
'AR-LB' => 'arabic',
'AR-LY' => 'arabic',
'AR-MA' => 'arabic',
'AR-OM' => 'arabic',
'AR-QA' => 'arabic',
'AR-SA' => 'arabic',
'AR-SY' => 'arabic',
'AR-TN' => 'arabic',
'AR-AE' => 'arabic',
'AR-YE' => 'arabic',
'AZ' => 'azerbaijani',
'CA' => 'catalan',
'ZH' => 'chinese',
'ZH-HK' => 'chinese',
'ZH-CN' => 'chinese',
'ZH-SG' => 'chinese',
'ZH-TW' => 'chinese',
'HR' => 'croatian',
'CS' => 'czech',
'DA' => 'danish',
'NL' => 'dutch',
'NL-BE' => 'dutch',
'EN' => 'english',
'EN-AU' => 'english',
'EN-BZ' => 'english',
'EN-CA' => 'english',
'EN-IE' => 'english',
'EN-JM' => 'english',
'EN-NZ' => 'english',
'EN-PH' => 'english',
'EN-ZA' => 'english',
'EN-TT' => 'english',
'EN-GB' => 'english',
'EN-US' => 'english',
'EN-ZW' => 'english',
'ET' => 'estonian',
'FA' => 'farsi',
'FR' => 'french',
'FR-BE' => 'french',
'FR-CA' => 'french',
'FR-FR' => 'french',
'FR-LU' => 'french',
'FR-MC' => 'french',
'FR-CH' => 'french',
'DE' => 'german',
'DE-AT' => 'german',
'DE-DE' => 'german',
'DE-LI' => 'german',
'DE-LU' => 'german',
'DE-CH' => 'german',
'HE' => 'hebrew',
'HU' => 'hungarian',
'IT' => 'italian',
'IT-CH' => 'italian',
'MK' => 'macedonian',
'NO' => 'norwegian',
'NB' => 'norwegian',
'NN' => 'norwegian',
'PT-BR' => 'portuguese-br',
'PT' => 'portuguese-pt',
'RO' => 'romanian',
'RO-MO' => 'romanian',
'RU' => 'russian',
'RU-MO' => 'russian',
'ES' => 'spanish',
'ES-AR' => 'spanish',
'ES-BO' => 'spanish',
'ES-CL' => 'spanish',
'ES-CO' => 'spanish',
'ES-CR' => 'spanish',
'ES-DO' => 'spanish',
'ES-EC' => 'spanish',
'ES-SV' => 'spanish',
'ES-GT' => 'spanish',
'ES-HN' => 'spanish',
'ES-MX' => 'spanish',
'ES-NI' => 'spanish',
'ES-PA' => 'spanish',
'ES-PY' => 'spanish',
'ES-PE' => 'spanish',
'ES-PR' => 'spanish',
'ES-ES' => 'spanish',
'ES-UY' => 'spanish',
'ES-VE' => 'spanish',
'SI' => 'slovenian',
'SV' => 'swedish',
'SV-FI' => 'swedish',
'SV-SV' => 'swedish',
'TR' => 'turkish',
'UK' => 'ukranian',
// NOTE: You can add more below
);

if(!isset($_SESSION['switch-language']) && $_SESSION['uid'] == false)
     {$_SESSION['switch-language'] = true; // prevent from redirecting back again in this session}

$current_country = strtoupper(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2));

$language = $current_country != '' && isset($country_to_language[$current_country])
? $country_to_language[$current_country]
: $country_to_language['default'];

if(!isset($_SESSION['Language']) || $_SESSION['Language'] != $language) {
    $location = '?language='.$language;
    if($_SERVER['QUERY_STRING'] != '' && strpos($_SERVER['QUERY_STRING'],'?language')===0)
      $location .= '&'.$_SERVER['QUERY_STRING'];
    ob_clean();
    header('location: '.$location);
    die();
    }

}

?>

 

 

 

 

 

Found this article interesting?
Subscribe to DomainRegister´s newsletter!

You can unsubscribe at any time by simply clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp s privacy practices here.

  • WHMCS
  • 0 uporabniku/om je bi članek v pomoč
Vam je bil odgovor v pomoč?

Povezani članki

 How to add a favicon in WHMCS

To add a favicon to your WHMCS install: copy your favicon (es. myfavicon.ico) in WHMCS folder...

 How to comment in template (.tpl) files

If you need to insert a comment in a .tpl file, or comment a block of code to disable it, you...

 How to insert a Youtube video in WHMCS knowledgebase article

To insert a YouTube video in an article of the WHMCS knowledge base, you need to insert following...

 How to disable a customer to pay invoices partly with credit balance

in WHMCS if a customer has not enough credit balance for full payment of an invoice, WHMCS allows...

 How to add a cookie bar to WHMCS

In order to add a cookie bar to your own installation of WHMCS: copy somewhere on your WHMCS...