#!/usr/bin/php Exgtract messages to translate"; class Extractor { protected $cnt; public function __construct() { } public function scanFile($file) { $this->scan(file_get_contents($file)); } public function scan($string) { $tokens = token_get_all($string); for ($i = 0; $i < count($tokens); ++$i) { $t = $tokens[$i]; if (!is_array($t)) { continue; } if ($t[0] == T_DOUBLE_COLON) { $left = $tokens[($i - 1)]; if ($left[0] != T_STRING || strtolower($left[1]) != 'pati18n' ) { continue; } $right = $tokens[($i + 1)]; if ($right[0] != T_STRING) { continue; } ++$i; $domain = null; switch (strtolower($right[1])) { case 'dgettext': $d = $this->getNextString($i, $tokens); $domain = $d[1]; // fall through case 'gettext': $t = $this->getNextString($i, $tokens); if (!$domain) { echo "gettext ". $t[1] . "\n"; } else { echo "dgettext domain: ". $d[1] . " msg: " . $t[1] . "\n"; } break; case 'dngettext': $d = $this->getNextString($i, $tokens); $domain = $d[1]; // fall through case 'ngettext': $s = $this->getNextString($i, $tokens); $p = $this->getNextString($i, $tokens); if (!$domain) { echo "ngettext singular: ". $s[1] . " plural: " . $p[1] . "\n"; } else { echo "dngettext " . "domain: " . $domain . " singular: ". $s[1] . " plural: " . $p[1] . "\n"; } break; default: continue; break; } } } } protected function getNextString(&$i, $tokens) { ++$i; while(true) { $t = $tokens[$i]; // skip "(" if (!is_array($t) && $t == '(') { ++$i; continue; } // skip blanks if (is_array($t) && $t[0] != T_WHITESPACE ) { break; } ++$i; } return $t; } } $e = new Extractor(); // MySQL $moduleConf = array( 'domain' => 'patI18n', 'domains' => array('patForms'), 'database' => 'pat', 'host' => 'localhost', 'user' => 'gerd', 'password' => 'gerd123', 'tablemsg' => 'i18nmsg', 'tabletrans'=> 'i18ntrans' ); echo 'add Module: MySQL
' . print_r( $moduleConf, true ) . '
'; $im = patI18n::createImporter('MySQL', $moduleConf); array_shift($_SERVER['argv']); foreach($_SERVER['argv'] as $f ) { echo "

$f

\n"; $e->scanFile($f); } ?>