public function ettext(\Latte\MacroNode $node, \Latte\PhpWriter $writer) { $this->setFunction($node->name); $args = h4kuna\Template\LattePhpTokenizer::toArray($node); $argsGettext = $this->getGettextArgs($args); $out = $this->function . '(' . implode(', ', $argsGettext) . ')'; $key = (int) (substr($this->function, 0, 1) == 'd'); $diff = $this->foundReplace($args[$key]); if ($diff) { $out = 'sprintf(' . $out . ', ' . implode(', ', array_slice($args, $diff)) . ')'; } $this->function = NULL; return $writer->write('echo %modify(' . $out . ')'); }
private static function getArgs(Latte\MacroNode $node) { $args = h4kuna\Template\LattePhpTokenizer::toArray($node); if (!isset($args[2])) { $args[2] = 'default'; } $args[2] = self::methodStringToInt(trim($args[2], '\'"')); $out = ''; $chars = ['"', "'", '$']; foreach ($args as $value) { if ($out) { $out .= ', '; } if (!is_numeric($value)) { $char = substr($value, 0, 1); if (!in_array($char, $chars)) { $value = '"' . $value . '"'; } } $out .= $value; } return $out; }