]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/language.php
Twitter bridge - pref setting to turn off sending @-replies to Twitter
[quix0rs-gnu-social.git] / lib / language.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22
23
24 function client_prefered_language($httplang) {
25         $client_langs = array();
26         $all_languages = get_all_languages();
27
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);
33                 }
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);
37                 }
38             }
39             #sort in decending q
40             arsort($client_langs);
41
42             foreach ($client_langs as $lang => $q) {
43                 if (isset($all_languages[$lang])) {
44                     return($all_languages[$lang]['lang']);
45                 }
46             }
47             return FALSE;
48 }
49
50 function get_nice_language_list() {
51         $nice_lang = array();
52         $all_languages = get_all_languages();
53         foreach ($all_languages as $lang) {
54                 $nice_lang = $nice_lang + array($lang['lang'] => $lang['name']);
55         }
56         return $nice_lang;
57 }
58
59 function get_all_languages() {
60         $all_languages = array(
61                             'en-us' => array('q' => 1, 'lang' => 'en_US', 'name' => 'English (US)', 'direction' => 'ltr'),
62                             'en-nz' => array('q' => 1, 'lang' => 'en_NZ', 'name' => 'English (NZ)', 'direction' => 'ltr'),
63                             'en-gb' => array('q' => 1, 'lang' => 'en_GB', 'name' => 'English (British)', 'direction' => 'ltr'),
64                             'en'    => array('q' => 1, 'lang' => 'en',    'name' => 'English', 'direction' => 'ltr'),
65                             'da'    => array('q' => 1, 'lang' => 'da_DK', 'name' => 'Danish', 'direction' => 'ltr'),
66                             'nl'    => array('q' => 1, 'lang' => 'nl_NL', 'name' => 'Dutch', 'direction' => 'ltr'),
67                             'eo'    => array('q' => 1, 'lang' => 'eo',    'name' => 'Esperanto', 'direction' => 'ltr'),
68                             'fr-fr' => array('q' => 1, 'lang' => 'fr_FR', 'name' => 'French', 'direction' => 'ltr'),
69                             'de'    => array('q' => 1, 'lang' => 'de_DE', 'name' => 'German', 'direction' => 'ltr'),
70                             'it'    => array('q' => 1, 'lang' => 'it_IT', 'name' => 'Italian', 'direction' => 'ltr'),
71                             'ko'    => array('q' => 1, 'lang' => 'ko',    'name' => 'Korean', 'direction' => 'ltr'),
72                             'nb'    => array('q' => 1, 'lang' => 'nb_NO', 'name' => 'Norwegian (bokmal)', 'direction' => 'ltr'),
73                             'pt'    => array('q' => 1, 'lang' => 'pt',    'name' => 'Portuguese', 'direction' => 'ltr'),
74                             'pt-br' => array('q' => 1, 'lang' => 'pt_BR', 'name' => 'Portuguese Brazil', 'direction' => 'ltr'),
75                             'ru'    => array('q' => 1, 'lang' => 'ru_RU', 'name' => 'Russian', 'direction' => 'ltr'),
76                             'es'    => array('q' => 1, 'lang' => 'es',    'name' => 'Spanish', 'direction' => 'ltr'),
77                             'tr'    => array('q' => 1, 'lang' => 'tr_TR', 'name' => 'Turkish', 'direction' => 'ltr'),
78                             'uk'    => array('q' => 1, 'lang' => 'uk_UA', 'name' => 'Ukrainian', 'direction' => 'ltr'),
79                         );
80         return $all_languages;
81 }