3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('LACONICA')) { exit(1); }
24 function client_prefered_language($httplang) {
25 $client_langs = array();
26 $all_languages = get_all_languages();
28 preg_match_all('"(((\S\S)-?(\S\S)?)(;q=([0-9.]+))?)\s*(,\s*|$)"',strtolower($httplang),$httplang);
29 for ($i = 0; $i < count($httplang); $i++) {
30 if(!empty($httplang[2][$i])) {
31 #if no q default to 1.0
32 $client_langs[$httplang[2][$i]] = ($httplang[6][$i]? (float) $httplang[6][$i] : 1.0);
34 if(!empty($httplang[3][$i]) && empty($client_langs[$httplang[3][$i]])) {
35 #if a catchall default 0.01 lower
36 $client_langs[$httplang[3][$i]] = ($httplang[6][$i]? (float) $httplang[6][$i]-0.01 : 0.99);
40 arsort($client_langs);
42 foreach ($client_langs as $lang => $q) {
43 if (isset($all_languages[$lang])) {
44 return($all_languages[$lang]['lang']);
50 function get_nice_language_list() {
52 $all_languages = get_all_languages();
53 foreach ($all_languages as $lang) {
54 $nice_lang = $nice_lang + array($lang['lang'] => $lang['name']);
59 function get_all_languages() {
60 $all_languages = array('en-us' => array('q' => 1, 'lang' => 'en_US', 'name' => 'English (US)', 'direction' => 'ltr'),
61 'en-nz' => array('q' => 1, 'lang' => 'en_NZ', 'name' => 'English (NZ)', 'direction' => 'ltr'),
62 'en' => array('q' => 1, 'lang' => 'en', 'name' => 'English', 'direction' => 'ltr'),
63 'fr-fr' => array('q' => 1, 'lang' => 'fr_FR', 'name' => 'French', 'direction' => 'ltr'),
65 return $all_languages;