r665: Renaming product from "BugStrike" to "Bugdar"
[bugdar.git] / includes / language.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Bugdar [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 // ###################################################################
14 // LEXICAL STRING CONSTANTS
15
16 $lang->setlex('error_invalid_id', $lang->string('That is an invalid ID.'));
17
18 // ###################################################################
19 // updates the localization cache
20 function build_language_cache($languageid)
21 {
22 global $bugsys;
23
24 $bugsys->db->query("DELETE FROM localization WHERE languageid = $languageid");
25
26 $localizations = fetch_strings($languageid, true);
27 foreach ($localizations AS $key => $value)
28 {
29 $bugsys->db->query("INSERT INTO localization (localkey, localtext, languageid) VALUES ('" . $bugsys->escape($key) . "', '" . $bugsys->escape($value) . "', $languageid)");
30 }
31 }
32
33 // ###################################################################
34 // fetches phrases from the system
35 function fetch_strings($languageid, $forcexml = false)
36 {
37 global $bugsys;
38
39 $language =& $bugsys->datastore['language']["$languageid"];
40
41 $locals = array();
42
43 if (!$language['languageid'])
44 {
45 return;
46 }
47
48 if ($language['debug'] OR $forcexml)
49 {
50 if (!file_exists($language['filename']))
51 {
52 trigger_error('Cannot load XML strings file', E_USER_WARNING);
53 return;
54 }
55
56 $xmldata = file_get_contents($language['filename']);
57 if ($xmldata === false)
58 {
59 trigger_error('Error reading XML strings file', E_USER_WARNING);
60 return;
61 }
62
63 $xml = $bugsys->xml->parse($xmldata);
64 foreach ($xml['localization']['string'] AS $string)
65 {
66 $locals[ $string['key']['value'] ] = $string['value']['value'];
67 }
68 }
69 else
70 {
71 $localizations = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "localization WHERE languageid = $languageid");
72 while ($local = $bugsys->db->fetch_array($localizations))
73 {
74 $locals["$local[localkey]"] = $local['localtext'];
75 }
76 $bugsys->db->free_result($localizations);
77 }
78
79 return $locals;
80 }
81
82 // ###################################################################
83 // determines the user's language
84 function fetch_user_language()
85 {
86 global $bugsys;
87
88 if ($bugsys->userinfo['userid'])
89 {
90 $languageid = $bugsys->userinfo['languageid'];
91 $language = $bugsys->datastore['language']["$languageid"];
92 }
93
94 if (!$languageid)
95 {
96 foreach ($bugsys->datastore['language'] AS $language)
97 {
98 if ($language['default'])
99 {
100 $languageid = $language['languageid'];
101 $language = $bugsys->datastore['language']["$languageid"];
102 break;
103 }
104 }
105 }
106
107 $lang['id'] = $language['languageid'];
108 $lang['charset'] = $language['charset'];
109 $lang['direction'] = $language['direction'];
110 $lang['code'] = $language['languagecode'];
111
112 return $lang;
113 }
114
115 /*=====================================================================*\
116 || ###################################################################
117 || # $HeadURL$
118 || # $Id$
119 || ###################################################################
120 \*=====================================================================*/
121 ?>