[phpwebapp-commits] CVS: web_app/parser class.WebObjectTpl.php,1.9,1.10 class.WebClassTpl.php,1.12,1
Brought to you by:
dashohoxha
From: Dashamir H. <das...@us...> - 2005-06-22 12:56:37
|
Update of /cvsroot/phpwebapp/web_app/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19477/parser Modified Files: class.WebObjectTpl.php class.WebClassTpl.php class.Render.php Log Message: - solved multiple lines problem - fixed some problems with translating JS messages Index: class.WebObjectTpl.php =================================================================== RCS file: /cvsroot/phpwebapp/web_app/parser/class.WebObjectTpl.php,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** class.WebObjectTpl.php 22 Jul 2004 16:25:37 -0000 1.9 --- class.WebObjectTpl.php 22 Jun 2005 12:56:28 -0000 1.10 *************** *** 81,84 **** --- 81,142 ---- } + /** This is called before the template is rendered. */ + function before_render() + { + global $tplVars, $l10n; + + //use another translation file, if such a file exists + $l10n->set_translation_file($this->class->path, $this->id); + + //save the current scope of the var stack + $this->scope = $tplVars->getCurrentScope(); + + //add state vars to the current scope + $tplVars->addVars($this->getSVars()); + + //add some special variables which identify this object + $tplVars->addVars($this->getObjVars()); + + //add parameters to the current scope + $tplVars->addVars($this->getParams()); + + //add the class url variable {{./}} + $class_path = $this->class->path; + $class_url = WebApp::to_url($class_path); + $tplVars->addVar("./", $class_url); + + //extract translatable messages in the JS code + $this->get_translatable_messages(); + + //call the function onRender of this WebObject + $this->onRender(); + } + + /** + * Extract translatable messages (which are denoted by T_("...") ) + * from a JS file, and save them in the associative array + * $webPage->js_i18n_messages + * Called by before_render() + */ + function get_translatable_messages() + { + $fname = $this->class->path.$this->id.".js"; + if (file_exists($fname)) + { + global $webPage; + $pattern = '#T_\("([^"]+)"\)#'; //match patterns like this: T_("....") + $js_code = file_get_contents($fname); + preg_match_all($pattern, $js_code, $matches); + for ($i=0; $i < sizeof($matches[1]); $i++) + { + $msgid = $matches[1][$i]; + $pattern = "\\\\n(\\\\ *\n)"; //replace '\n' by newline + $msgid = ereg_replace($pattern, "\n\\1", $msgid); + $msgstr = T_($msgid); + $webPage->js_i18n_messages[$msgid] = $msgstr; + } + } + } + /** * This function is called by beforeParse(). Index: class.WebClassTpl.php =================================================================== RCS file: /cvsroot/phpwebapp/web_app/parser/class.WebClassTpl.php,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** class.WebClassTpl.php 21 Jun 2005 08:39:51 -0000 1.12 --- class.WebClassTpl.php 22 Jun 2005 12:56:28 -0000 1.13 *************** *** 127,137 **** $include_js = " <script type=\"text/javascript\" language=\"javascript\" src=\"$fname\"></script>\n"; $webPage->append_to_head($include_js); - - //extract translatable messages in the JS code - $pattern = '#T_\("([^"]+)"\)#'; //match patterns like this: T_("....") - $js_code = file_get_contents($fname); - preg_match_all($pattern, $js_code, $matches); - $webPage->js_i18n_messages = - array_merge($webPage->js_i18n_messages, $matches[1]); } } --- 127,130 ---- Index: class.Render.php =================================================================== RCS file: /cvsroot/phpwebapp/web_app/parser/class.Render.php,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** class.Render.php 13 Jun 2005 14:24:17 -0000 1.23 --- class.Render.php 22 Jun 2005 12:56:28 -0000 1.24 *************** *** 318,350 **** } ! //use another translation file, if such a file exists ! global $l10n; $l10n->pushState(); ! $l10n->set_translation_file($wobj_tpl->class->path, $wobj_tpl->id); ! ! //create a new variable scope ! global $tplVars; ! $tplVars->pushScope(); ! ! //save the current scope of the var stack ! $wobj_tpl->scope = $tplVars->getCurrentScope(); ! ! //add state vars to the current scope ! $tplVars->addVars($wobj_tpl->getSVars()); ! ! //add some special variables which identify this object ! $tplVars->addVars($wobj_tpl->getObjVars()); ! ! //add parameters to the current scope ! $tplVars->addVars($wobj_tpl->getParams()); ! ! //add the class url variable {{./}} ! $class_path = $wobj_tpl->class->path; ! ! $class_url = WebApp::to_url($class_path); ! $tplVars->addVar("./", $class_url); ! //call the function onRender of this WebObject ! $wobj_tpl->onRender(); $this->render_tpl($wobj_tpl); //render it to HTML --- 318,326 ---- } ! global $tplVars, $l10n; $l10n->pushState(); ! $tplVars->pushScope(); //create a new variable scope ! $wobj_tpl->before_render(); $this->render_tpl($wobj_tpl); //render it to HTML |