/** * Returns the translation of a string * * @param string $subject * @param string $var_1 * @param string $var2 * @param string $var_n * @return string */ public function translate($subject, $var_1 = '', $var2 = '', $var_n = '') { $args = func_get_args(); $variables = array(); if (1 < count($args)) { foreach ($args as $key => $value) { $variables['%' . $key] = $value; } } unset($variables['%0']); return I18N::getInstance('messages', Domains::getInstance()->getLanguage())->getTranslation($subject, $variables); }
/** * Parses a locale definition file following the POSIX standard * * @param resource $file file handler * @param string $domain Domain where locale definitions will be stored * @return void * @access private */ function __loadLocaleDefinition($file, $domain = null) { $_this =& I18N::getInstance(); $comment = '#'; $escape = '\\'; $currentToken = false; $value = ''; while ($line = fgets($file)) { $line = trim($line); if (empty($line) || $line[0] === $comment) { continue; } $parts = preg_split("/[[:space:]]+/", $line); if ($parts[0] === 'comment_char') { $comment = $parts[1]; continue; } if ($parts[0] === 'escape_char') { $escape = $parts[1]; continue; } $count = count($parts); if ($count == 2) { $currentToken = $parts[0]; $value = $parts[1]; } elseif ($count == 1) { $value .= $parts[0]; } else { continue; } $len = strlen($value) - 1; if ($value[$len] === $escape) { $value = substr($value, 0, $len); continue; } $mustEscape = array($escape . ',', $escape . ';', $escape . '<', $escape . '>', $escape . $escape); $replacements = array_map('crc32', $mustEscape); $value = str_replace($mustEscape, $replacements, $value); $value = explode(';', $value); $_this->__escape = $escape; foreach ($value as $i => $val) { $val = trim($val, '"'); $val = preg_replace_callback('/(?:<)?(.[^>]*)(?:>)?/', array(&$this, '__parseLiteralValue'), $val); $val = str_replace($replacements, $mustEscape, $val); $value[$i] = $val; } if (count($value) == 1) { $this->__domains[$this->category][$this->__lang][$domain][$currentToken] = array_pop($value); } else { $this->__domains[$this->category][$this->__lang][$domain][$currentToken] = $value; } } }
// random salt to code file names define("ERRORLEVEL_NONE", 0); define("ERRORLEVEL_FATAL", 1); // errors that prevent from running the tests define("ERRORLEVEL_CRITICAL", 2); // security threats or inacceptable errors define("ERRORLEVEL_WARNING", 3); define("ERRORLEVEL_SUCCESS", 4); define("ERRORLEVEL_INFO", 5); define("TC_CONTACT_MAIL", "*****@*****.**"); define("TC_CONTACT_NAME", "Guillaume Baudhuin"); date_default_timezone_set('UTC'); global $g_creationDate; $g_creationDate = time(); if (!defined("USE_DB")) { define("USE_DB", true); } // True to save validation history in database. False to avoid history saving, but keep all other functionalities // **************************************************************************** // Init // **************************************************************************** if (USE_DB) { include_once TC_ROOTDIR . '/DB/History.php'; } include_once TC_INCDIR . '/Route.php'; include_once TC_INCDIR . '/I18N.php'; // initialize I18N $i18n = I18N::getInstance(); // initialize usermessages include_once TC_INCDIR . '/UserMessage.php'; $userMessage = UserMessage::getInstance();
public static function __($key, $lang = null) { $l = $lang; global $ExistingLangs; if (empty($lang) || !in_array($lang, $ExistingLangs)) { $i18n = I18N::getInstance(); $l = $i18n->curLang; } if (isset($_SESSION["i18n_texts"][$l][$key])) { return $_SESSION["i18n_texts"][$l][$key]; } else { return $key; } }
public function __construct() { $this->includeClasses(); $this->instance = Bootstrap::$instance; $this->language = Domains::getInstance()->getLanguage(); $this->url_definition = Urls::getInstance($this->instance)->getUrlDefinition(); $urls = Urls::getInstance($this->instance)->getUrlConfig(); $current_url = $this->getUrl(Urls::getInstance(Bootstrap::$instance)->getPath(), Urls::getInstance($this->instance)->getParams()); $urls['current_url'] = $current_url; $this->params = array('current_url' => $current_url, 'instance' => Bootstrap::$instance, 'controller' => get_class($this), 'path' => Urls::getInstance($this->instance)->getPath(), 'path_parts' => Urls::getInstance($this->instance)->getPathParts(), 'params' => Urls::getInstance($this->instance)->getParams(), 'has_debug' => Domains::getInstance()->getDebugMode(), 'lang' => $this->language, 'url' => $urls); // Init i18n configuration. $this->i18n = I18N::getInstance(Domains::getInstance()->getLanguageDomain(), $this->language); // Parse Key-Value parameters $this->params['parsed_params'] = $this->parseParams(); $this->params['page'] = $this->getCurrentPage(); $this->cache = Cache::getInstance(Cache::CACHE_TYPE_AUTODISCOVER); $this->view = new View(); }
public function assemble($route = array()) { $i18n = I18N::getInstance(); $lang = ""; if (isset($route["lang"])) { if ($route["lang"] == TC_DEFAULT_LANG) { $lang = ""; } else { $lang = $route["lang"]; } } $url = ""; if (!empty($lang)) { $url = $lang . '/'; } if (!isset($route["phpfile"])) { return "Error : phpfile not defined"; } if ($route["phpfile"] == "home") { $url = trim($url, '/ '); } else { if ($route["phpfile"] == "results") { $data = array(); if (isset($route["hash"])) { $url = trim($url . $i18n->url($route["lang"], 'score'), '/ '); if (!USE_DB) { echo 'error in route. cannot assemble route without DB'; die; } $history = new History(); $themeInfo = $history->loadThemeFromHash($route["hash"]); if (empty($themeInfo)) { return null; } $data["name"] = $themeInfo->namesanitized; if ($themeInfo->themetype == TT_WORDPRESS) { $data["themetype"] = 'wordpress_theme'; } if ($themeInfo->themetype == TT_JOOMLA) { $data["themetype"] = 'joomla_template'; } if ($themeInfo->themetype == TT_WORDPRESS_CHILD) { $data["themetype"] = 'wordpress_theme'; } $url .= '/' . trim($i18n->url($route["lang"], $data["themetype"])) . '_' . trim($data["name"]) . '.html'; } else { if (isset($route["namesanitized"]) && isset($route["themetype"])) { $url = trim($url . $i18n->url($route["lang"], 'score'), '/ '); if ($route["themetype"] == TT_WORDPRESS) { $data["themetype"] = 'wordpress_theme'; } if ($route["themetype"] == TT_JOOMLA) { $data["themetype"] = 'joomla_template'; } if ($route["themetype"] == TT_WORDPRESS_CHILD) { $data["themetype"] = 'wordpress_theme'; } $url .= '/' . trim($i18n->url($route["lang"], $data["themetype"])) . '_' . trim($route["namesanitized"]) . '.html'; } else { if (isset($route["ut"])) { $url = trim($url . $i18n->url($route["lang"], 'score'), '/ ') . '?ut=' . urlencode($route["ut"]); } else { $url = trim($url . $i18n->url($route["lang"], 'score'), '/ '); } } } } else { if ($route["phpfile"] == "unittests") { $url = trim($url . $i18n->url($route["lang"], 'unittests'), '/ '); } else { if ($route["phpfile"] == "massimport") { $url = "massimport"; } else { if ($route["phpfile"] == "contact") { $url = trim($url . $i18n->url($route["lang"], 'contact'), '/ '); } else { if ($route["phpfile"] == "error404.php") { $url = trim($url . $i18n->url($route["lang"], $route["phpfile"]), '/ '); } } } } } } return strtolower($url); }