Mercurial > SimpleWebPresenter
comparison accept-language.inc @ 54:f938b292f046
Something went wrong during last merge. Fix it now.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Thu, 11 Oct 2012 00:57:16 +0200 |
| parents | 2e6ba7259281 |
| children | 88482c6636c4 |
comparison
equal
deleted
inserted
replaced
| 53:2e6ba7259281 | 54:f938b292f046 |
|---|---|
| 1 <?php | 1 <?php |
| 2 <<<<<<< local | |
| 3 class Language { | |
| 4 function acceptedLanguages() { | |
| 5 $langs = array(); | |
| 6 ======= | |
| 7 /** | 2 /** |
| 8 * @file | 3 * @file |
| 9 * Functionality for determining language use | 4 * Functionality for determining language use |
| 10 */ | 5 */ |
| 6 class Language { | |
| 7 function acceptedLanguages() { | |
| 8 $langs = array(); | |
| 11 | 9 |
| 12 /** | 10 /** |
| 13 * Extracts the accepted languages from the GET query, sorted by | 11 * Extracts the accepted languages from the GET query, sorted by |
| 14 * preference(q-value). | 12 * preference(q-value). |
| 15 * | 13 * |
| 16 * @return associative array of language codes with q value | 14 * @return associative array of language codes with q value |
| 17 */ | 15 */ |
| 18 function acceptedLanguages() { | 16 function acceptedLanguages() { |
| 19 $langs = array(); | 17 $langs = array(); |
| 20 >>>>>>> other | |
| 21 | 18 |
| 22 if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { | 19 if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
| 23 // break up string into pieces (languages and q factors) | 20 // break up string into pieces (languages and q factors) |
| 24 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); | 21 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); |
| 25 | 22 |
| 26 if (count($lang_parse[1])) { | 23 if (count($lang_parse[1])) { |
| 27 // create a list like "en" => 0.8 | 24 // create a list like "en" => 0.8 |
| 28 $langs = array_combine($lang_parse[1], $lang_parse[4]); | 25 $langs = array_combine($lang_parse[1], $lang_parse[4]); |
| 29 | 26 |
| 30 // set default to 1 for any without q factor | 27 // set default to 1 for any without q factor |
| 31 foreach ($langs as $lang => $val) { | 28 foreach ($langs as $lang => $val) { |
| 32 if ($val === '') $langs[$lang] = 1; | 29 if ($val === '') $langs[$lang] = 1; |
| 33 } | 30 } |
| 34 | 31 |
| 35 // sort list based on value | 32 // sort list based on value |
| 36 arsort($langs, SORT_NUMERIC); | 33 arsort($langs, SORT_NUMERIC); |
| 37 } | |
| 38 } | |
| 39 return $langs; | |
| 40 } | |
| 41 | |
| 42 function preferLanguage($prefer) | |
| 43 { | |
| 44 $language = $prefer; | |
| 45 $langs = acceptedLanguages(); | |
| 46 if ($langs) { | |
| 47 foreach ($langs as $l => $val) { | |
| 48 if (file_exists($l)) { | |
| 49 $language = $l; | |
| 50 break; | |
| 51 } | 34 } |
| 52 } | 35 } |
| 36 return $langs; | |
| 53 } | 37 } |
| 54 return $language; | 38 |
| 39 function preferLanguage($prefer) | |
| 40 { | |
| 41 $language = $prefer; | |
| 42 $langs = acceptedLanguages(); | |
| 43 if ($langs) { | |
| 44 foreach ($langs as $l => $val) { | |
| 45 if (file_exists($l)) { | |
| 46 $language = $l; | |
| 47 break; | |
| 48 } | |
| 49 } | |
| 50 } | |
| 51 return $language; | |
| 52 } | |
| 55 } | 53 } |
| 56 } | 54 } |
| 57 ?> | 55 ?> |
