*/ /** * patTemplate gettext / patI18n wrapper * * Utilize patI18n to translate template snippets * * @version 0.1.0 * @package Wombat * @subpackage patTemplate */ class patTemplate_Function_Gettext extends patTemplate_Function { /** * name of the function * @access private * @var string */ public $_name = 'Gettext'; /** * call the function * * Use patI18n to translate contetn. * * Attributes: * - domain: text domain * * @param array parameters of the function (= attributes of the tag) * @param string content of the tag * @return string content to insert into the template */ public function call($params, $content) { // nothing to do if (empty($content)) { return ''; } $params = array_merge(array( 'domain' => '', 'wxml' => 'auto' ), $params); // translate with domain if (!empty($params['domain'])) { $msg = patI18n::dgettext($params['domain'], $content); } else { // use default domain $msg = patI18n::gettext($content); } $this->runWXml($msg, $params); return $msg; } /** * Run WXML markup handler * * Check parameter "wxml" * * @param string $msg * @param array $params */ public function runWXml(&$msg, $params) { if (empty($params['wxml']) || '0' == $params['wxml']) { return; } // check for HTML tags if ('auto' == $params['wxml']) { $wLen = strlen($msg); $oLen = strlen(strip_tags($msg)); if ($wLen == $oLen) { return; } } $scan = WBClass::create( 'WBMarkup_Scanner' ); /* @var $scan WBMarkup_Scanner */ $hdl = WBClass::create( 'WBMarkup_Handler_Xml2Html' ); /* @var $hdl WBMarkup_Handler_Xml2Html */ if (isset($params['tmpldir']) && !empty($params['tmpldir'])) { $hdl->setTmplDir($params['tmpldir']); } $scan->setHandler($hdl); $scan->scan($msg); $msg = $hdl->getParsedContent(); } }