10 defined(
'JPATH_PLATFORM') or die;
27 protected static $strings = array();
46 public static function _($string, $jsSafe =
false, $interpretBackSlashes =
true, $script =
false)
50 if (is_array($jsSafe))
52 if (array_key_exists(
'interpretBackSlashes', $jsSafe))
54 $interpretBackSlashes = (boolean) $jsSafe[
'interpretBackSlashes'];
57 if (array_key_exists(
'script', $jsSafe))
59 $script = (boolean) $jsSafe[
'script'];
62 if (array_key_exists(
'jsSafe', $jsSafe))
64 $jsSafe = (boolean) $jsSafe[
'jsSafe'];
72 if (!(strpos($string,
',') ===
false))
74 $test = substr($string, strpos($string,
','));
76 if (strtoupper($test) === $test)
78 $strs = explode(
',', $string);
80 foreach ($strs as $i => $str)
82 $strs[$i] = $lang->_($str, $jsSafe, $interpretBackSlashes);
86 self::$strings[$str] = $strs[$i];
90 $str = array_shift($strs);
91 $str = preg_replace(
'/\[\[%([0-9]+):[^\]]*\]\]/',
'%\1$s', $str);
92 $str = vsprintf($str, $strs);
100 self::$strings[$string] = $lang->_($string, $jsSafe, $interpretBackSlashes);
106 return $lang->_($string, $jsSafe, $interpretBackSlashes);
127 public static function alt($string, $alt, $jsSafe =
false, $interpretBackSlashes =
true, $script =
false)
131 if ($lang->hasKey($string .
'_' . $alt))
133 return self::_($string .
'_' . $alt, $jsSafe, $interpretBackSlashes, $script);
137 return self::_($string, $jsSafe, $interpretBackSlashes, $script);
168 public static function plural($string, $n)
171 $args = func_get_args();
172 $count = count($args);
178 $suffixes = $lang->getPluralSuffixes((
int) $n);
179 array_unshift($suffixes, (
int) $n);
181 foreach ($suffixes as $suffix)
183 $key = $string .
'_' . $suffix;
185 if ($lang->hasKey($key))
198 if (is_array($args[$count - 1]))
201 $key, array_key_exists(
'jsSafe', $args[$count - 1]) ? $args[$count - 1][
'jsSafe'] :
false,
202 array_key_exists(
'interpretBackSlashes', $args[$count - 1]) ? $args[$count - 1][
'interpretBackSlashes'] :
true
205 if (array_key_exists(
'script', $args[$count - 1]) && $args[$count - 1][
'script'])
207 self::$strings[$key] = call_user_func_array(
'sprintf', $args);
214 $args[0] = $lang->_($key);
217 return call_user_func_array(
'sprintf', $args);
222 $args[0] = $lang->_($string);
224 return call_user_func_array(
'sprintf', $args);
251 public static function sprintf($string)
254 $args = func_get_args();
255 $count = count($args);
259 if (is_array($args[$count - 1]))
262 $string, array_key_exists(
'jsSafe', $args[$count - 1]) ? $args[$count - 1][
'jsSafe'] :
false,
263 array_key_exists(
'interpretBackSlashes', $args[$count - 1]) ? $args[$count - 1][
'interpretBackSlashes'] :
true
266 if (array_key_exists(
'script', $args[$count - 1]) && $args[$count - 1][
'script'])
268 self::$strings[$string] = call_user_func_array(
'sprintf', $args);
275 $args[0] = $lang->_($string);
278 $args[0] = preg_replace(
'/\[\[%([0-9]+):[^\]]*\]\]/',
'%\1$s', $args[0]);
280 return call_user_func_array(
'sprintf', $args);
297 public static function printf($string)
300 $args = func_get_args();
301 $count = count($args);
305 if (is_array($args[$count - 1]))
308 $string, array_key_exists(
'jsSafe', $args[$count - 1]) ? $args[$count - 1][
'jsSafe'] :
false,
309 array_key_exists(
'interpretBackSlashes', $args[$count - 1]) ? $args[$count - 1][
'interpretBackSlashes'] :
true
314 $args[0] = $lang->_($string);
317 return call_user_func_array(
'printf', $args);
334 public static function script($string = null, $jsSafe =
false, $interpretBackSlashes =
true)
336 if (is_array($jsSafe))
338 if (array_key_exists(
'interpretBackSlashes', $jsSafe))
340 $interpretBackSlashes = (boolean) $jsSafe[
'interpretBackSlashes'];
343 if (array_key_exists(
'jsSafe', $jsSafe))
345 $jsSafe = (boolean) $jsSafe[
'jsSafe'];
354 if ($string !== null)
357 self::$strings[strtoupper($string)] =
JFactory::getLanguage()->_($string, $jsSafe, $interpretBackSlashes);
360 return self::$strings;