r433: Merging the locale-change branch onto trunk; we now use ISSO's localize system
[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 // fetches phrases from the system
20 function fetch_phrases($languageid, $forcexml = false)
21 {
22 global $bugsys;
23
24 $language =& $bugsys->datastore['language']["$languageid"];
25
26 $locals = array();
27
28 if ($language['debug'] OR $forcexml)
29 {
30 if (!file_exists($language['filename']))
31 {
32 trigger_error('Cannot load XML strings file', E_USER_ERROR);
33 }
34
35 $xmldata = file_get_contents($language['filename']);
36 if ($xmldata === false)
37 {
38 trigger_error('Error reading XML strings file', E_USER_ERROR);
39 }
40
41 $xml = $bugsys->xml->parse($xmldata);
42 foreach ($xml['language']['phrase'] AS $phrase)
43 {
44 $locals[ $phrase['key']['value'] ] = $phrase['value']['value'];
45 }
46 }
47 else
48 {
49 $localizations = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "localization WHERE languageid = $languageid");
50 while ($local = $bugsys->db->fetch_array($localizations))
51 {
52 $locals["$local[localkey]"] = $local['localtext'];
53 }
54 $bugsys->db->free_result($localizations);
55 }
56
57 return $locals;
58 }
59
60 // ###################################################################
61 // determines the user's language
62 function fetch_user_language()
63 {
64 global $bugsys;
65
66 if ($bugsys->userinfo['userid'])
67 {
68 $languageid = $bugsys->userinfo['languageid'];
69 $language = $bugsys->datastore['language']["$languageid"];
70 }
71
72 if (!$languageid)
73 {
74 foreach ($bugsys->datastore['language'] AS $language)
75 {
76 if ($language['default'])
77 {
78 $languageid = $language['languageid'];
79 $language = $bugsys->datastore['language']["$languageid"];
80 break;
81 }
82 }
83 }
84
85 $lang['id'] = $language['languageid'];
86 $lang['charset'] = $language['charset'];
87 $lang['direction'] = $language['direction'];
88 $lang['code'] = $language['languagecode'];
89
90 return $lang;
91 }
92
93 /*=====================================================================*\
94 || ###################################################################
95 || # $HeadURL$
96 || # $Id$
97 || ###################################################################
98 \*=====================================================================*/
99 ?>