Composr : tempcode symbol : visitors language

Let us talk about scripts, HTML, Perl, PHP, apache, etc.
User avatar
Stevyn
SysOp
Posts:1786
Joined:Mon Nov 09, 2009 10:03 am
Location:Japan
Contact:
Composr : tempcode symbol : visitors language

Post by Stevyn » Thu Jul 25, 2019 9:52 pm

https://compo.sr/forum/topicview/browse ... mpcode.htm

https://stackoverflow.com/questions/603 ... r-variable

sources/hooks/systems/symbols/BROWSERLANG.php

Code: Select all

<?php

class Hook_symbol_BROWSERLANG
{

    public function run($param)
    {
    //start
    $value="en";
   if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse);
  if (count($lang_parse[1])){
    $langs = array_combine($lang_parse[1], $lang_parse[4]);
    foreach ($langs as $lang => $val){
      if ($val === '') $langs[$lang] = 1;
    }
    arsort($langs, SORT_NUMERIC);
  }
  foreach ($langs as $lang => $val){
    if (strpos($lang,'en')===0){
      $value = 'en';
      break;
    } else if (strpos($lang,'ja')===0){
      $value = 'ja';
    }
  }
} 
    
    
    
    
    
  //end
  //  
            
        return $value;
    }
}

example usage:

Code: Select all

{+START,IF,{$NEQ,$BROWSERLANG,ja}}
This is info for non-japanese speakers.
{+END}
Contact me directly: Ironfeatherbooks (@) gmail.com

Image

Post Reply