From 6dd211530fea743dedf142ced4ccd6c87e5ed54b Mon Sep 17 00:00:00 2001 From: "matthew.gregg" Date: Fri, 18 Jul 2008 20:34:17 -0400 Subject: Patch for PITS 00032, 00033, 00034 darcs-hash:20080719003417-982e4-7004f8a4dfb447f941457c30b0b2289eee5582e6.gz --- lib/language.php | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 lib/language.php (limited to 'lib/language.php') diff --git a/lib/language.php b/lib/language.php new file mode 100644 index 000000000..c3532d744 --- /dev/null +++ b/lib/language.php @@ -0,0 +1,66 @@ +. + */ + +if (!defined('LACONICA')) { exit(1); } + + + +function client_prefered_language($httplang) { + $client_langs = array(); + $all_languages = get_all_languages(); + + preg_match_all('"(((\S\S)-?(\S\S)?)(;q=([0-9.]+))?)\s*(,\s*|$)"',strtolower($httplang),$httplang); + for ($i = 0; $i < count($httplang); $i++) { + if(!empty($httplang[2][$i])) { + #if no q default to 1.0 + $client_langs[$httplang[2][$i]] = ($httplang[6][$i]? (float) $httplang[6][$i] : 1.0); + } + if(!empty($httplang[3][$i]) && empty($client_langs[$httplang[3][$i]])) { + #if a catchall default 0.01 lower + $client_langs[$httplang[3][$i]] = ($httplang[6][$i]? (float) $httplang[6][$i]-0.01 : 0.99); + } + } + #sort in decending q + arsort($client_langs); + + foreach ($client_langs as $lang => $q) { + if (isset($all_languages[$lang])) { + return($all_languages[$lang]['lang']); + } + } + return FALSE; +} + +function get_nice_language_list() { + $nice_lang = array(); + $all_languages = get_all_languages(); + foreach ($all_languages as $lang) { + $nice_lang = $nice_lang + array($lang['lang'] => $lang['name']); + } + return $nice_lang; +} + +function get_all_languages() { + $all_languages = array('en-us' => array('q' => 1, 'lang' => 'en_US', 'name' => 'English (US)', 'direction' => 'ltr'), + 'en-nz' => array('q' => 1, 'lang' => 'en_NZ', 'name' => 'English (NZ)', 'direction' => 'ltr'), + 'en' => array('q' => 1, 'lang' => 'en', 'name' => 'English', 'direction' => 'ltr'), + 'fr-fr' => array('q' => 1, 'lang' => 'fr_FR', 'name' => 'French', 'direction' => 'ltr'), + ); + return $all_languages; +} -- cgit v1.2.3-54-g00ecf