r435: - added build_language_cache() to cache the XML data for languages
[bugdar.git] / includes / language.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]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_phrases($language['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_phrases($languageid, $forcexml = false)
36 {
37 global $bugsys;
38
39 $language =& $bugsys->datastore['language']["$languageid"];
40
41 $locals = array();
42
43 if ($language['debug'] OR $forcexml)
44 {
45 if (!file_exists($language['filename']))
46 {
47 trigger_error('Cannot load XML strings file', E_USER_ERROR);
48 }
49
50 $xmldata = file_get_contents($language['filename']);
51 if ($xmldata === false)
52 {
53 trigger_error('Error reading XML strings file', E_USER_ERROR);
54 }
55
56 $xml = $bugsys->xml->parse($xmldata);
57 foreach ($xml['language']['phrase'] AS $phrase)
58 {
59 $locals[ $phrase['key']['value'] ] = $phrase['value']['value'];
60 }
61 }
62 else
63 {
64 $localizations = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "localization WHERE languageid = $languageid");
65 while ($local = $bugsys->db->fetch_array($localizations))
66 {
67 $locals["$local[localkey]"] = $local['localtext'];
68 }
69 $bugsys->db->free_result($localizations);
70 }
71
72 return $locals;
73 }
74
75 // ###################################################################
76 // determines the user's language
77 function fetch_user_language()
78 {
79 global $bugsys;
80
81 if ($bugsys->userinfo['userid'])
82 {
83 $languageid = $bugsys->userinfo['languageid'];
84 $language = $bugsys->datastore['language']["$languageid"];
85 }
86
87 if (!$languageid)
88 {
89 foreach ($bugsys->datastore['language'] AS $language)
90 {
91 if ($language['default'])
92 {
93 $languageid = $language['languageid'];
94 $language = $bugsys->datastore['language']["$languageid"];
95 break;
96 }
97 }
98 }
99
100 $lang['id'] = $language['languageid'];
101 $lang['charset'] = $language['charset'];
102 $lang['direction'] = $language['direction'];
103 $lang['code'] = $language['languagecode'];
104
105 return $lang;
106 }
107
108 /*=====================================================================*\
109 || ###################################################################
110 || # $HeadURL$
111 || # $Id$
112 || ###################################################################
113 \*=====================================================================*/
114 ?>