expression,$m)) { if ($m[1]=='structure') $escape=false; $this->expression = isset($m[2])?$m[2]:''; } // if no expression is given, the content of the node is used as // a translation key if (strlen(trim($this->expression)) == 0){ $key = $this->_getTranslationKey($this->tag, !$escape); $key = trim(preg_replace('/\s+/sm'.($this->tag->generator->getEncoding()=='UTF-8'?'u':''), ' ', $key)); $code = '\'' . str_replace('\'', '\\\'', $key) . '\''; } else { $code = $this->tag->generator->evaluateExpression($this->expression); } $this->_prepareNames($this->tag); $php = sprintf('echo $_translator->translate(%s,%s);', $code, $escape ? 'true':'false'); $this->tag->generator->pushCode($php); } public function end() { } private function _getTranslationKey($tag, $preserve_tags) { $result = ''; foreach ($tag->children as $child){ if ($child instanceOf PHPTAL_Php_Text){ $result .= $child->node->getValue(); } else if ($child instanceOf PHPTAL_Php_Element){ if ($child->hasAttribute('i18n:name')){ $value = $child->getAttribute('i18n:name'); $result .= '${' . $value . '}'; } else { if ($preserve_tags) { $result .= '<'.$child->name; foreach($child->attributes as $k => $v) { $result .= ' '.$k.'="'.$v.'"'; } $result .= '>'.$this->_getTranslationKey($child, $preserve_tags).'name.'>'; } else { $result .= $this->_getTranslationKey($child, $preserve_tags); } } } } return $result; } private function _prepareNames($tag) { foreach ($tag->children as $child){ if ($child instanceOf PHPTAL_Php_Element){ if ($child->hasAttribute('i18n:name')){ $child->generate(); } else { $this->_prepareNames($child); } } } } } ?>