Pleas Note : in "logaty/core/detect_visitor_language.php" file you can found the best way to detect visitor language.
Browser Language

Detect Browser Language

you need to enable detect_browser_lang option from config .php

How to use ?


use PHPtricks\Logaty\Classes\Detect;
$detect = new Detect();
echo $detect->browser();
// return browser language code-2-digits
    

for example if browser language is arabic the method will be return (ar)
and if browser language is english the method will be return (en)

Full Example


use PHPtricks\Logaty\Classes\Detect;
$detect = new Detect();
$browserLanguage = $detect->browser();

if($browserLanguage !== currentLang())
{
    showModal([
        'type'     => 'browser',
        'language' => $browserLanguage,
    ]);
}
function showModal($options = [])
{
    if(!isset($_SESSION['detect']))
    {
        $_SESSION['detect'] = true;
        // show modal or message box or do what you want
    }
}
                        






Country Language

Detect Country Language

you need to enable detect_countyr_lang option from config.ini

How to use ?


use PHPtricks\Logaty\Classes\Detect;

$detect = new Detect();
echo $detect->country();
// return country language code-2-digits - if we cant found it
    

for example if country language is arabic the method will br return (ar)
and if country language is english the method will br return (en)

Full Example


use PHPtricks\Logaty\Classes\Detect;

$detect = new Detect();
$countryLanguage = $detect->country();

if($countryLanguage !== currentLang())
{
    showModal([
    'type'     => 'country',
    'language' => $countryLanguage,
    ]);
}
function showModal($options = [])
{
    if(!isset($_SESSION['detect']))
    {
        $_SESSION['detect'] = true;
        // show modal or message box or do what you want
    }
}