/** * Translates the text with subsititution. * @param string text for translation * @param array list of substitutions * @return string translated text */ protected function translateText($text, $subs) { $app = $this->getApplication()->getGlobalization(); //no translation handler provided if (($config = $app->getTranslationConfiguration()) === null) { return strtr($text, $subs); } $catalogue = $this->getCatalogue(); if (empty($catalogue) && isset($config['catalogue'])) { $catalogue = $config['catalogue']; } if (empty($catalogue)) { $catalogue = 'messages'; } Translation::init($catalogue); $key = $this->getKey(); if (!empty($key)) { $text = $key; } //translate it return Translation::formatter($catalogue)->format($text, $subs, $catalogue, $this->getCharset()); }
/** * Localize a text to the locale/culture specified in the globalization handler. * @param string text to be localized. * @param array a set of parameters to substitute. * @param string a different catalogue to find the localize text. * @param string the input AND output charset. * @return string localized text. * @see TTranslate::formatter() * @see TTranslate::init() */ public static function localize($text, $parameters = array(), $catalogue = null, $charset = null) { $app = Prado::getApplication()->getGlobalization(false); $params = array(); foreach ($parameters as $key => $value) { $params['{' . $key . '}'] = $value; } //no translation handler provided if ($app === null || ($config = $app->getTranslationConfiguration()) === null) { return strtr($text, $params); } if ($catalogue === null) { $catalogue = isset($config['catalogue']) ? $config['catalogue'] : 'messages'; } Translation::init($catalogue); //globalization charset $appCharset = $app === null ? '' : $app->getCharset(); //default charset $defaultCharset = $app === null ? 'UTF-8' : $app->getDefaultCharset(); //fall back if (empty($charset)) { $charset = $appCharset; } if (empty($charset)) { $charset = $defaultCharset; } return Translation::formatter($catalogue)->format($text, $params, $catalogue, $charset); }