split up get_browser_language() to use in additional ways

This commit is contained in:
friendica 2012-07-16 01:38:26 -07:00
parent c148455570
commit b79212dcc8
4 changed files with 17 additions and 3 deletions

View File

@ -827,6 +827,8 @@ function item_store($arr,$force_parent = false) {
$arr['body'] = strip_tags($arr['body']); $arr['body'] = strip_tags($arr['body']);
$arr['lang'] = detect_language($arr['body']); $arr['lang'] = detect_language($arr['body']);
$arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0); $arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0);

View File

@ -19,6 +19,8 @@
if(! function_exists('get_browser_language')) { if(! function_exists('get_browser_language')) {
function get_browser_language() { function get_browser_language() {
$langs = array();
if (x($_SERVER,'HTTP_ACCEPT_LANGUAGE')) { if (x($_SERVER,'HTTP_ACCEPT_LANGUAGE')) {
// break up string into pieces (languages and q factors) // 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', preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i',
@ -37,6 +39,16 @@ function get_browser_language() {
arsort($langs, SORT_NUMERIC); arsort($langs, SORT_NUMERIC);
} }
} }
else
$langs['en'] = 1;
return $langs;
}}
function get_best_language() {
$langs = get_browser_language();
if(isset($langs) && count($langs)) { if(isset($langs) && count($langs)) {
foreach ($langs as $lang => $v) { foreach ($langs as $lang => $v) {
@ -52,7 +64,7 @@ function get_browser_language() {
$a = get_app(); $a = get_app();
return ((isset($a->config['system']['language'])) ? $a->config['system']['language'] : 'en'); return ((isset($a->config['system']['language'])) ? $a->config['system']['language'] : 'en');
}} }
function push_lang($language) { function push_lang($language) {

View File

@ -27,7 +27,7 @@ $install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false
@include(".htconfig.php"); @include(".htconfig.php");
$lang = get_browser_language(); $lang = get_best_language();
load_translation_table($lang); load_translation_table($lang);

View File

@ -11,7 +11,7 @@ require_once("boot.php");
$a = new App; $a = new App;
@include(".htconfig.php"); @include(".htconfig.php");
$lang = get_browser_language(); $lang = get_best_language();
load_translation_table($lang); load_translation_table($lang);
require_once("dba.php"); require_once("dba.php");