Add the current language information to the response data.
[bugdar.git] / includes / language.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2002-2007 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 // ###################################################################
23 // LEXICAL STRING CONSTANTS
24
25 define('L_INVALID_ID', T('That is an invalid ID.'));
26
27 // ###################################################################
28 // determines the user's language
29 function fetch_user_language()
30 {
31 $language = NULL;
32 if (Bugdar::$user['userid']) {
33 $languageid = Bugdar::$user['languageid'];
34 $language = Bugdar::$datastore['language']["$languageid"];
35 }
36
37 if (!$language && is_array(Bugdar::$datastore['language'])) {
38 foreach (Bugdar::$datastore['language'] AS $language) {
39 if (Bugdar::$options['defaultlanguage'] == $language['languageid']) {
40 $languageid = $language['languageid'];
41 $language = Bugdar::$datastore['language']["$languageid"];
42 break;
43 }
44 }
45 }
46
47 return array(
48 'id' => $language['languageid'],
49 'charset' => $language['charset'],
50 'direction' => $language['direction'],
51 'langcode' => $language['langcode'],
52 );
53 }
54
55 /**
56 * Translation function. This will take in a native (English) string and return either
57 * a translated version or, if it cannot find one, the native string back.
58 *
59 * @param string Native string
60 *
61 * @return string Translated string
62 */
63 function T($str)
64 {
65 global $bugsys;
66 static $mo;
67
68 if ($mo === null)
69 {
70 require_once './includes/class_mo.php';
71 $info = fetch_user_language();
72 if ($info['langcode'] == null)
73 {
74 $bugsys->debug("cannot translate '$str'");
75 return $str;
76 }
77 $mo = new MOReader("locale/$info[langcode]/LC_MESSAGES/messages.mo");
78 }
79
80 return $mo->T($str);
81 }
82