r1048: Converting all $lang->string() stuff to use the gettext call
[bugdar.git] / includes / language.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] 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 [#]gpl[#] 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 $lang->setlex('error_invalid_id', _('That is an invalid ID.'));
26
27 // ###################################################################
28 // updates the localization cache
29 function build_language_cache($languageid)
30 {
31 global $bugsys;
32
33 $bugsys->db->query("DELETE FROM " . TABLE_PREFIX . "localization WHERE languageid = $languageid");
34
35 $localizations = fetch_strings($languageid, true);
36 foreach ($localizations AS $key => $value)
37 {
38 $bugsys->db->query("INSERT INTO " . TABLE_PREFIX . "localization (localkey, localtext, languageid) VALUES ('" . $bugsys->escape($key) . "', '" . $bugsys->escape($value) . "', $languageid)");
39 }
40 }
41
42 // ###################################################################
43 // fetches phrases from the system
44 function fetch_strings($languageid, $forcexml = false)
45 {
46 global $bugsys;
47
48 $language =& $bugsys->datastore['language']["$languageid"];
49
50 $locals = array();
51
52 if (!$language['languageid'])
53 {
54 return;
55 }
56
57 if ($language['debug'] OR $forcexml)
58 {
59 if (!file_exists($language['filename']))
60 {
61 trigger_error('Cannot load XML strings file', E_USER_WARNING);
62 return;
63 }
64
65 $xmldata = file_get_contents($language['filename']);
66 if ($xmldata === false)
67 {
68 trigger_error('Error reading XML strings file', E_USER_WARNING);
69 return;
70 }
71
72 $xml = $bugsys->xml->parse($xmldata);
73 foreach ($xml['localization']['string'] AS $string)
74 {
75 $locals[ $string['key']['value'] ] = $string['value']['value'];
76 }
77 }
78 else
79 {
80 $localizations = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "localization WHERE languageid = $languageid");
81 while ($local = $bugsys->db->fetch_array($localizations))
82 {
83 $locals["$local[localkey]"] = $local['localtext'];
84 }
85 $bugsys->db->free_result($localizations);
86 }
87
88 return $locals;
89 }
90
91 // ###################################################################
92 // determines the user's language
93 function fetch_user_language()
94 {
95 global $bugsys;
96
97 if ($bugsys->userinfo['userid'])
98 {
99 $languageid = $bugsys->userinfo['languageid'];
100 $language = $bugsys->datastore['language']["$languageid"];
101 }
102
103 if (!$languageid AND is_array($bugsys->datastore['language']))
104 {
105 foreach ($bugsys->datastore['language'] AS $language)
106 {
107 if ($bugsys->options['defaultlanguage'] == $language['languageid'])
108 {
109 $languageid = $language['languageid'];
110 $language = $bugsys->datastore['language']["$languageid"];
111 break;
112 }
113 }
114 }
115
116 $lang['id'] = $language['languageid'];
117 $lang['charset'] = $language['charset'];
118 $lang['direction'] = $language['direction'];
119 $lang['code'] = $language['languagecode'];
120
121 return $lang;
122 }
123
124 /*=====================================================================*\
125 || ###################################################################
126 || # $HeadURL$
127 || # $Id$
128 || ###################################################################
129 \*=====================================================================*/
130 ?>