Co jsi nasel?
Co jsi hledal?
Dej to sem a popis, co to dela nebo nedela?
google = detect language by ip php
google = detect state by ip php
function getLanguage(){
$a=@explode(array(',',';'),$_SERVER['HTTP_ACCEPT_LANGUAGE']);
return $a[0];
}
function getPreferredLanguage() {
$langs = array();
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
// break up string into pieces (languages and q factors)
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])) {
// create a list like "en" => 0.8
$langs = array_combine($lang_parse[1], $lang_parse[4]);
// set default to 1 for any without q factor
foreach ($langs as $lang => $val) {
if ($val === '') $langs[$lang] = 1;
}
// sort list based on value
arsort($langs, SORT_NUMERIC);
}
}
//extract most important (first)
foreach ($langs as $lang => $val) { break; }
//if complex language simplify it
if (stristr($lang,"-")) {$tmp = explode("-",$lang); $lang = $tmp[0]; }
return $lang;
}
http://php.net/manual/en/book.geoip.php
Pomoci tretich stran https://www.youtube.com/watch?…
//checks if the language exists, if not choose the default language
if (!$cookie->id_lang && isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
{
$array = explode(',', Tools::strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']));
if (Tools::strlen($array[0]) > 2)
{
$tab = explode('-', $array[0]);
$string = $tab[0];
}
else
$string = $array[0];
if (Validate::isLanguageIsoCode($string))
{
$lang = new Language(Language::getIdByIso($string));
if (Validate::isLoadedObject($lang) && $lang->active)
$this->id_lang = (int)$lang->id;
}
}
//checks if the language exists, if not choose the default language
if (!Language::getLanguage((int)$this->id_lang))
$this->id_lang = Configuration::get('PS_LANG_DEFAULT');
}
public static function setCookieLanguage($cookie = null)
{
if (!$cookie)
$cookie = Context::getContext()->cookie;
/* If language does not exist or is disabled, erase it */
if ($cookie->id_lang)
{
$lang = new Language((int)$cookie->id_lang);
if (!Validate::isLoadedObject($lang) || !$lang->active || !$lang->isAssociatedToShop())
$cookie->id_lang = null;
}
/* Automatically detect language if not already defined, detect_language is set in Cookie::update */
if ((!$cookie->id_lang || isset($cookie->detect_language)) && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$array = explode(',', Tools::strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])
);
...
5 min googlovani. Jestli neco z toho dela, co potrebujes, pak se styd :)