Check if Acccept-Language header is empty before using it
This commit is contained in:
parent
0094d7cbbd
commit
607234d727
4 changed files with 9 additions and 4 deletions
|
|
@ -1,8 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
require_once("language/language.php");
|
require_once("language/language.php");
|
||||||
|
|
||||||
|
header("Access-Control-Allow-Origin: *");
|
||||||
|
|
||||||
$lang = Language::getPreferredLanguage();
|
$lang = Language::getPreferredLanguage();
|
||||||
echo $lang->get("Test");
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,5 @@ class English extends Language {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new English();
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,11 @@ class Language {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getPreferredLanguage() {
|
public static function getPreferredLanguage() {
|
||||||
$language = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
if (empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||||
|
$language = "en";
|
||||||
|
} else {
|
||||||
|
$language = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||||
|
}
|
||||||
|
|
||||||
$languages = array(
|
$languages = array(
|
||||||
"en",
|
"en",
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,5 @@ class Dutch extends Language {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new Dutch();
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue