Fix DB_MySQL_PDO::escape_binary().
[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 global $bugsys;
32
33 if ($bugsys->userinfo['userid'])
34 {
35 $languageid = $bugsys->userinfo['languageid'];
36 $language = bugdar::$datastore['language']["$languageid"];
37 }
38
39 if (!$languageid AND is_array(bugdar::$datastore['language']))
40 {
41 foreach (bugdar::$datastore['language'] AS $language)
42 {
43 if ($bugsys->options['defaultlanguage'] == $language['languageid'])
44 {
45 $languageid = $language['languageid'];
46 $language = bugdar::$datastore['language']["$languageid"];
47 break;
48 }
49 }
50 }
51
52 $lang['id'] = $language['languageid'];
53 $lang['charset'] = $language['charset'];
54 $lang['direction'] = $language['direction'];
55 $lang['langcode'] = $language['langcode'];
56
57 return $lang;
58 }
59
60 /**
61 * Translation function. This will take in a native (English) string and return either
62 * a translated version or, if it cannot find one, the native string back.
63 *
64 * @param string Native string
65 *
66 * @return string Translated string
67 */
68 function T($str)
69 {
70 global $bugsys;
71 static $mo;
72
73 if ($mo === null)
74 {
75 require_once './includes/class_mo.php';
76 $info = fetch_user_language();
77 if ($info['langcode'] == null)
78 {
79 $bugsys->debug("cannot translate '$str'");
80 return $str;
81 }
82 $mo = new MOReader("locale/$info[langcode]/LC_MESSAGES/messages.mo");
83 }
84
85 return $mo->T($str);
86 }
87