- Update the copyright notices to use the correct year and not a non-ASCII symbol
[bugdar.git] / includes / language.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2004-2008 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 // for those who don't have gettext
24
25 if (!function_exists('gettext'))
26 {
27 function gettext($str) { return $str; }
28 function _($str) { return $str; }
29 function bindtextdomain() {}
30 function textdomain() {}
31 function bind_textdomain_codeset() {}
32
33 BSApp::debug('NOTICE: gettext not installed');
34 }
35
36 // ###################################################################
37 // LEXICAL STRING CONSTANTS
38
39 define('L_INVALID_ID', T('That is an invalid ID.'));
40
41 // ###################################################################
42 // determines the user's language
43 function fetch_user_language()
44 {
45 if (bugdar::$userinfo['userid'])
46 {
47 $languageid = bugdar::$userinfo['languageid'];
48 $language = bugdar::$datastore['language']["$languageid"];
49 }
50
51 if (!$languageid AND is_array(bugdar::$datastore['language']))
52 {
53 foreach (bugdar::$datastore['language'] AS $language)
54 {
55 if (bugdar::$options['defaultlanguage'] == $language['languageid'])
56 {
57 $languageid = $language['languageid'];
58 $language = bugdar::$datastore['language']["$languageid"];
59 break;
60 }
61 }
62 }
63
64 $lang['id'] = $language['languageid'];
65 $lang['charset'] = $language['charset'];
66 $lang['direction'] = $language['direction'];
67 $lang['langcode'] = $language['langcode'];
68
69 return $lang;
70 }
71
72 /**
73 * Translation function. This will take in a native (English) string and return either
74 * a translated version or, if it cannot find one, the native string back. If the devgettext
75 * setting is enabled, this will use MOReader to load a .mo file, otherwise it will fall back onto
76 * making a call to _(), the built-in Gettext implementation.
77 *
78 * @param string Native string
79 *
80 * @return string Translated string
81 */
82 function T($str)
83 {
84 static $mo;
85
86 if (!bugdar::$options['devgettext'])
87 {
88 return _($str);
89 }
90
91 if ($mo === null)
92 {
93 require_once './includes/class_mo.php';
94 $info = fetch_user_language();
95 if ($info['langcode'] == null)
96 {
97 BSApp::debug("cannot translate '$str'");
98 return $str;
99 }
100 $mo = new MOReader("locale/$info[langcode]/LC_MESSAGES/messages.mo");
101 }
102
103 return $mo->T($str);
104 }
105
106 ?>