Composr : tempcode symbol : visitors language
Posted: 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
example usage:
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;
}
}
Code: Select all
{+START,IF,{$NEQ,$BROWSERLANG,ja}}
This is info for non-japanese speakers.
{+END}