getParameterOption(['--file']); $all = $input->hasParameterOption(['--all']); $templates = getAllTemplateFiles($dir); if (empty($file) && empty($all)) { error('Params not found. ' . PHP_EOL . 'Valid params: --file [file], --all'); die(); } if (! empty($file)) { $file = $dir . '/' . $file; if (! in_array($file, $templates) || ! file_exists($file)) { error('File not found or is not .tpl'); die(); } $message = ''; $check = check($file); if (isset($check)) { $message .= $check . PHP_EOL; } if (! empty($message)) { info(color('File has ":" or "," outside of translation in the following lines in red:', 'yellow')); info(trim($message, PHP_EOL)); exit(1); } else { info(basename($file) . ' ' . color('OK', 'green')); } } if (! empty($all)) { $message = ''; foreach ($templates as $file) { $check = check($file); if (isset($check)) { $message .= $check . PHP_EOL; } } if (! empty($message)) { info(color('The following files have ":" or "," outside of translation in the following lines in red:', 'yellow')); info(trim($message, PHP_EOL)); exit(1); } else { important('All template files OK'); } } function getAllTemplateFiles($currentDir) { $templateDir = new RecursiveDirectoryIterator($currentDir . '/../../templates'); $ite = new RecursiveIteratorIterator($templateDir); $files = new RegexIterator($ite, '/.*tpl/', RegexIterator::GET_MATCH); $templateList = []; foreach ($files as $file) { if (file_exists($file[0])) { $templateList = array_merge($templateList, $file); } } return $templateList; } function check($file) { if (file_exists($file)) { $message = realpath($file); $lineNumber = ''; if ($fileHandler = fopen($file, "r")) { $i = 0; while ($line = fgets($fileHandler)) { $i++; if (strpos($line, '{/tr}:') !== false || strpos($line, '{/tr},') !== false) { $lineNumber .= $i . ","; } } fclose($fileHandler); } if (! empty($lineNumber)) { return color($message . ':', 'blue') . color(substr($lineNumber, 0, -1), 'red'); } } }