]>
src.bluestatic.org Git - bugdar.git/blob - includes/class_language.php
2 /*=====================================================================*\
3 || ################################################################### ||
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 \*=====================================================================*/
14 * Language management class. Because this uses Simpleton we want to
15 * keep names as short as short as possible
19 var $language = array();
23 * Singleton initializer
25 * @param integer Language ID
26 * @return object An instance of the class
28 function init($languageid = 0)
34 $instance = new lang();
35 $instance->load($instance->select());
42 * Initializes the language system by fetching the appropriate language
44 * @param integer Language ID
46 function load($languageid)
50 $phrases = $bugsys->db
->query("
51 (SELECT varname, phrasetext FROM " . TABLE_PREFIX
. "phrase)
53 (SELECT varname, phrasetext FROM " . TABLE_PREFIX
. "locale WHERE languageid = " . intval($languageid) . ")"
55 while ($phrase = $bugsys->db
->fetch_array($phrases))
57 $this->language
["$phrase[varname]"] = $phrase['phrasetext'];
59 $bugsys->db
->free_result($phrases);
63 * Selects the proper language for the user
65 * @return integer The language ID that will be used
71 if ($bugsys->userinfo
['userid'])
73 $languageid = $bugsys->userinfo
['languageid'];
74 $language = $bugsys->datastore
['language']["$languageid"];
78 foreach ($bugsys->datastore['language'] AS $language)
80 if ($language['default'])
82 $languageid = $language['languageid'];
83 $language = $bugsys->datastore['language']["$languageid"];
89 $this->vars
['id'] = $language['languageid'];
90 $this->vars
['charset'] = $language['charset'];
91 $this->vars
['direction'] = $language['direction'];
92 $this->vars
['code'] = $language['languagecode'];
98 * Fetches a phrase from the language array
100 * @param string Phrase name
101 * @return string The phrase text
103 function fetch_phrase($phrasename)
105 return $this->language
["$phrasename"];
109 * Takes a phrase name and the arguments for it and constructs it
111 * @param string Phrase name
112 * @param arguments Values for the arguments the phrase takes
113 * @return string Processed phrase
117 $obj =& lang::init();
119 $args = func_get_args();
120 $numargs = sizeof($args);
127 if ($phrasetext = $obj->fetch_phrase($args[0]))
129 if (define('DEBUG_LOCALIZE'))
131 return '[[LOCALIZED: ' . $args[0] . ']]';
136 $phrase = $phrasetext;
140 $args[0] = $phrasetext;
141 if (($phrase = @call_user_func_array('sprintf', $args)) === false)
144 $bugsys->debug("$args[0] reported an
sprintf() error
; parsing manually
");
146 for ($i = 1; $i < $numargs; $i++)
148 $phrase = str_replace("%{$i
}\$s
", $args["$i"], $args[0]);
152 return preg_replace('#%([0-9].*?)\$s#', '<strong>[ARG \\1: UNDEFINED]</strong>', $phrase);
156 return "<strong>[UNDEFINED PHRASE: $args[0]]</strong>";
163 * Registers a phrase with the temporary text system
165 * @param string Phrase text
167 * @return string Phrase text
173 $mdstring = md5($string);
175 if ($regphrase = $bugsys->db
->query_first("SELECT * FROM phrase WHERE md5 = '$mdstring'"))
177 return $regphrase['phrasetext'];
181 $bt = debug_backtrace();
182 $btstr = $bt[0]['file'] . ':' . $bt[0]['line'];
184 $bugsys->db->query("REPLACE INTO
phraseregistry (md5
, phrasetext
, file
) VALUES ('$mdstring', '" . $bugsys->sanitize($string) . "', '$btstr')");
191 * Fetches a variable from the vars array
193 * @param string Variable name
194 * @return mixed The value of the variable
196 function fetch_var($varname)
198 return $this->vars["$varname"];
202 * Returns a variable about the language system
204 * @param string The name of the variable
205 * @return mixed The value fof the variable
209 $obj =& lang
::init();
210 return $obj->fetch_var($varname);
214 /*=====================================================================*\
215 || ###################################################################
218 || ###################################################################
219 \*=====================================================================*/