private function searchInFile($filePath) { try { $file = new SplFileObject($filePath); } catch (Exception $e) { fwrite(STDERR, $e->getMessage() . "\n"); exit(0); } $fileContent = file_get_contents($file->getPathname()); if ($blockMatches = $this->blockMatcher($fileContent)) { for ($i = 0; $i < count($blockMatches[0]); $i++) { $offset = $blockMatches[3][$i][1]; $lineNumber = substr_count(substr($fileContent, 0, $offset), "\n") + 1; if (preg_match('/plural\\s*=\\s*["\']?\\s*(.[^\\"\']*)\\s*["\']?/', $blockMatches[2][$i][0], $match)) { $this->pgObject->setPlural($blockMatches[3][$i][0], $match[1], $filePath, $lineNumber); } else { $this->pgObject->setSingular($blockMatches[3][$i][0], $filePath, $lineNumber); } } } if ($modifierMatches = $this->modifierMatcher($fileContent)) { for ($i = 0; $i < count($modifierMatches[0]); $i++) { $offset = $modifierMatches[4][$i][1]; $lineNumber = substr_count(substr($fileContent, 0, $offset), "\n") + 1; $this->pgObject->setSingular($modifierMatches[4][$i][0], $filePath, $lineNumber); } } }
#!/usr/bin/env php <?php ini_set('display_errors', 'off'); use SmartyTranslate\Extractor; use SmartyTranslate\GettextCli; use SmartyTranslate\GettextGenerator; include "Vendor/autoload.php"; $extractor = new Extractor(); $gtCli = new GettextCli($_SERVER['argv']); $gtGenerator = new GettextGenerator(); if (php_sapi_name() === 'cli') { foreach ($gtCli->getFiles() as $file) { $extractor->extractFile($file); } } else { die("<br><b>You should run scanner.php in cli mode.</b>"); } echo $gtGenerator->generate();