]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/language.php
Wrap notice-saving code in a transaction
[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 function client_prefered_language($httplang) {
23         $client_langs = array();
24         $all_languages = common_config('site','languages');
25
26         preg_match_all('"(((\S\S)-?(\S\S)?)(;q=([0-9.]+))?)\s*(,\s*|$)"',strtolower($httplang),$httplang);
27         for ($i = 0; $i < count($httplang); $i++) {
28              if(!empty($httplang[2][$i])) {
29                     #if no q default to 1.0
30                     $client_langs[$httplang[2][$i]] = ($httplang[6][$i]? (float) $httplang[6][$i] : 1.0);
31                 }
32                 if(!empty($httplang[3][$i]) && empty($client_langs[$httplang[3][$i]])) {
33                     #if a catchall default 0.01 lower
34                     $client_langs[$httplang[3][$i]] = ($httplang[6][$i]? (float) $httplang[6][$i]-0.01 : 0.99);
35                 }
36             }
37             #sort in decending q
38             arsort($client_langs);
39
40             foreach ($client_langs as $lang => $q) {
41                 if (isset($all_languages[$lang])) {
42                     return($all_languages[$lang]['lang']);
43                 }
44             }
45             return FALSE;
46 }
47
48 function get_nice_language_list() {
49         $nice_lang = array();
50         $all_languages = common_config('site','languages');
51         foreach ($all_languages as $lang) {
52                 $nice_lang = $nice_lang + array($lang['lang'] => $lang['name']);
53         }
54         return $nice_lang;
55 }
56
57 // Get a list of all languages that are enabled in the default config. This
58 // should ONLY be called when setting up the default config in common.php.
59 // Any other attempt to get a list of lanugages should instead call
60 // common_config('site','languages')
61 function get_all_languages() {
62         return array(
63                 'bg' => array('q' => 0.8, 'lang' => 'bg_BG', 'name' => 'Bulgarian', 'direction' => 'ltr'),
64                 'ca'    => array('q' => 0.5, 'lang' => 'ca_ES', 'name' => 'Catalan', 'direction' => 'ltr'),
65                 'cs'    => array('q' => 0.5, 'lang' => 'cs_CZ', 'name' => 'Czech', 'direction' => 'ltr'),
66                 'de'    => array('q' => 0.5, 'lang' => 'de_DE', 'name' => 'German', 'direction' => 'ltr'),
67                 'el'    => array('q' => 0.1, 'lang' => 'el',    'name' => 'Greek', 'direction' => 'ltr'),
68                 'en-us' => array('q' => 1, 'lang' => 'en_US', 'name' => 'English (US)', 'direction' => 'ltr'),
69                 'en-gb' => array('q' => 0.3, 'lang' => 'en_GB', 'name' => 'English (British)', 'direction' => 'ltr'),
70                 'en'    => array('q' => 1, 'lang' => 'en',    'name' => 'English', 'direction' => 'ltr'),
71                 'es'    => array('q' => 0.5, 'lang' => 'es',    'name' => 'Spanish', 'direction' => 'ltr'),
72                 'fr-fr' => array('q' => 0.2, 'lang' => 'fr_FR', 'name' => 'French', 'direction' => 'ltr'),
73                 'he'    => array('q' => 0.5, 'lang' => 'he_IL', 'name' => 'Hebrew', 'direction' => 'ltr'),
74                 'it'    => array('q' => 0.9, 'lang' => 'it_IT', 'name' => 'Italian', 'direction' => 'rtl'),
75                 'jp'    => array('q' => 0.5, 'lang' => 'ja_JP', 'name' => 'Japanese', 'direction' => 'ltr'),
76 #               'ko'    => array('q' => 0, 'lang' => 'ko',    'name' => 'Korean', 'direction' => 'ltr'),
77                 'mk'    => array('q' => 0.5, 'lang' => 'mk_MK', 'name' => 'Macedonian', 'direction' => 'ltr'),
78                 'nb'    => array('q' => 0.1, 'lang' => 'nb_NO', 'name' => 'Norwegian (bokmal)', 'direction' => 'ltr'),
79                 'nl'    => array('q' => 0.5, 'lang' => 'nl_NL', 'name' => 'Dutch', 'direction' => 'ltr'),
80                 'pl'    => array('q' => 0.5, 'lang' => 'pl_PL', 'name' => 'Polish', 'direction' => 'ltr'),
81 #               'pt'    => array('q' => 0, 'lang' => 'pt',    'name' => 'Portuguese', 'direction' => 'ltr'),
82                 'pt-br' => array('q' => 0.7, 'lang' => 'pt_BR', 'name' => 'Portuguese Brazil', 'direction' => 'ltr'),
83                 'ru'    => array('q' => 0.1, 'lang' => 'ru_RU', 'name' => 'Russian', 'direction' => 'ltr'),
84                 'sv'    => array('q' => 0.9, 'lang' => 'sv_SE', 'name' => 'Swedish', 'direction' => 'ltr'),
85                 'te'    => array('q' => 0.3, 'lang' => 'te_IN', 'name' => 'Telugu', 'direction' => 'ltr'),
86                 'tr'    => array('q' => 0.5, 'lang' => 'tr_TR', 'name' => 'Turkish', 'direction' => 'ltr'),
87                 'uk'    => array('q' => 0.7, 'lang' => 'uk_UA', 'name' => 'Ukrainian', 'direction' => 'ltr'),
88                 'vi'    => array('q' => 0.7, 'lang' => 'vi_VN', 'name' => 'Vietnamese', 'direction' => 'ltr'),
89                 'zh-cn'    => array('q' => 0.9, 'lang' => 'zh_CN', 'name' => 'Chinese (Simplified)', 'direction' => 'ltr'),
90                 'zh-hant'    => array('q' => 0.2, 'lang' => 'zh_hant', 'name' => 'Chinese (Taiwanese)', 'direction' => 'ltr'),
91         );
92 }
93