*/ WBClass::load('patI18n'); /** * patTemplate modifier Wxml * * Convert Wombat XML format to HTML * * Parameter: * - tmpldir * - gettext: use gettext for translation * - domain: gettext domain * - mode: "html" or "tex" * * @package patTemplate * @package Modifiers * @author gERD Schaufelberger */ class patTemplate_Modifier_Wxml extends patTemplate_Modifier { /** * modify the value * * @param string value * @param array list of parameter * @return string modified value */ public function modify($value, $params = array()) { $params = array_merge(array( 'domain' => '', 'gettext' => '', 'tmpldir' => '', 'handler' => '', // deprecated 'mode' => 'html' ), $params); /* @var $scan WBMarkup_Scanner */ $scan = WBClass::create( 'WBMarkup_Scanner' ); // accept deprecated parameter "handler" if (!empty($params['handler'])) { $params['mode'] = $params['handler']; } switch (strtolower($params['mode'])) { case 'tex': /** @var WBMarkup_Handler_Xml2Tex */ $hdl = WBClass::create( 'WBMarkup_Handler_Xml2Tex' ); break; default: /** @var WBMarkup_Handler_Xml2Html */ $hdl = WBClass::create( 'WBMarkup_Handler_Xml2Html' ); break; } $hdl->setOption($params); if (!empty($params['tmpldir'])) { $hdl->setTmplDir($params['tmpldir']); } $value = $this->translate($value, $params); $scan->setHandler($hdl); $scan->scan($value); $value = $hdl->getParsedContent(); return $value; } /** * Translate the value * * @param string value * @param array list of parameter * @return string translated value */ private function translate($value, $params) { if (empty($params['gettext'])) { return $value; } if (!empty($params['domain'])) { return patI18n::dgettext($params['domain'], $value); } return patI18n::gettext($value); } }