static function __init() { self::$cache = array(); $adapter = $CONFIG['translator.adapter'] ? 'adapter_translator_' . $CONFIG['translator.adapter'] : __CLASS__; self::$adapter = new $adapter($CONFIG['translator.options']); self::$adapter->open(); }
protected function tagT(&$token) { if ('\\T' === strtoupper($this->nsResolved)) { ++$this->index; if ($this->dependencies['ConstantExpression']->nextExpressionIsConstant()) { if ($_SERVER['PATCHWORK_LANG']) { // Add the string to the translation table \TRANSLATOR::get($this->expressionValue, $_SERVER['PATCHWORK_LANG'], false); } } else { $this->register($this->callbacks = array('tagConcat' => array(T_CURLY_OPEN, T_DOLLAR_OPEN_CURLY_BRACES, '.'), 'tagTClose' => T_BRACKET_CLOSE)); } --$this->index; } }
protected function evalVar($a, $translate = false, $forceType = false) { if ('' === $a) { return "''"; } if ('~' === $a) { $a = 'g$__BASE__'; } if ('/' === $a) { $a = 'g$__HOST__'; } if ('"' === $a[0] || "'" === $a[0]) { $b = '"' === $a[0]; if (!$b) { $a = '"' . substr(preg_replace('/(?<!\\\\)((?:\\\\\\\\)*)"/su', '$1\\\\"', $a), 1, -1) . '"'; } $a = preg_replace("/(?<!\\\\)\\\\((?:\\\\\\\\)*)'/su", '$1\'', $a); $a = preg_replace('/(?<!\\\\)((\\\\?)(?:\\\\\\\\)*)\\$/su', '$1$2\\\\$', $a); $a = eval("return {$a};"); if ($b && '' !== trim($a)) { if ($translate) { $a = TRANSLATOR::get($a, Patchwork::__LANG__(), false); /**/ if (DEBUG) { Patchwork::watch('debugSync'); } } else { $this->mode = 'concat'; $this->concat = array(''); $this->concatLast = 0; $this->makeVars($a); if (!$this->concatLast) { $this->concat[0] = TRANSLATOR::get($this->concat[0], Patchwork::__LANG__(), false); /**/ if (DEBUG) { Patchwork::watch('debugSync'); } } for ($i = 0; $i <= $this->concatLast; $i += 2) { if ('' !== $this->concat[$i]) { $this->concat[$i] = $this->makeVar("'" . $this->concat[$i]); } else { unset($this->concat[$i]); } } $this->mode = 'echo'; return count($this->concat) > 1 ? $this->getConcat($this->concat) : current($this->concat); } } $a = "'" . $a; } else { if (preg_match("/^{$this->Xnumber}\$/su", $a)) { $a = eval("return \"'\" . {$a};"); } else { if (!preg_match("/^(?:{$this->Xvar}|[dag]\\\$|\\\$+)\$/su", $a)) { $a = preg_split("/({$this->Xvar}|{$this->Xnumber})/su", $a, -1, PREG_SPLIT_DELIM_CAPTURE); $i = 1; $len = count($a); while ($i < $len) { $a[$i - 1] = trim($a[$i - 1]); $b = $i > 1 && '-' === $a[$i][0] && '' === $a[$i - 1]; $a[$i] = $this->evalVar($a[$i], false, 'number'); if ($b && '0' === $a[$i]) { $a[$i - 1] = '-'; } $i += 2; } $a = implode($a); return $a; } } } return $this->makeVar($a, $forceType); }
function T($string, $lang = false) { if (!$lang) { $lang = Patchwork::__LANG__(); } return TRANSLATOR::get($string, $lang, true); }