]>
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]))
131 $phrase = $phrasetext;
135 $args[0] = $phrasetext;
136 if (($phrase = @call_user_func_array('sprintf', $args)) === false)
139 $bugsys->debug("$args[0] reported an
sprintf() error
; parsing manually
");
141 for ($i = 1; $i < $numargs; $i++)
143 $phrase = str_replace("%{$i
}\$s
", $args["$i"], $args[0]);
147 return preg_replace('#%([0-9].*?)\$s#', '<strong>[ARG \\1: UNDEFINED]</strong>', $phrase);
151 return "<strong>[UNDEFINED PHRASE: $args[0]]</strong>";
158 * Fetches a variable from the vars array
160 * @param string Variable name
161 * @return mixed The value of the variable
163 function fetch_var($varname)
165 return $this->vars
["$varname"];
169 * Returns a variable about the language system
171 * @param string The name of the variable
172 * @return mixed The value fof the variable
176 $obj =& lang::init();
177 return $obj->fetch_var($varname);
181 /*=====================================================================*\
182 || ###################################################################
185 || ###################################################################
186 \*=====================================================================*/