/** * Check a file for translation errors * @todo remove 2 loops, compare keys with array sort */ private function onCheckFile($path2) { $this->num_files++; $path1 = $this->getOtherPath($path2); # English file exists? if (!file_exists($path1) || !is_file($path1) || !is_readable($path1)) { $this->MissingFile['en'][] = $path1; $this->errors['en']++; $lang1 = false; } else { # TODO: try{} to catch syntax errors?! include $path1; if (!isset($lang) || empty($lang)) { $this->EmptyFile['en'][] = $path1; $this->errors['en']++; $lang = false; } $lang1 = $lang; unset($lang); } # same paths? if ($path1 === $path2) { $lang2 = false; } elseif (!file_exists($path2) || !is_file($path2) || !is_readable($path2)) { # if $lang1 is false or empty, the error lies within the english file, not the translation one if (false !== $lang1 && !empty($lang1)) { $this->MissingFile['tr'][] = $path2; $this->missing['tr']++; } $lang2 = false; } else { include $path2; if (!isset($lang)) { $this->EmptyFile['tr'][] = $path2; $this->errors['tr']++; $lang = false; } $lang2 = $lang; unset($lang); } # separation between errors/warns related to english files and errors in tranaltion files $errs = array('en' => array(), 'tr' => array()); $warn = array('en' => array(), 'tr' => array()); # Check if there really is a lang to check if (is_array($lang1)) { # English lang file foreach ($lang1 as $key => $value) { # Value is empty? if ($value === '') { $errs['en'][] = $this->module->lang('err_empty_key', array($key)); continue; } # other ISO lang file if ($lang2 === false) { continue; } # Key exists? if (false === isset($lang2[$key])) { $errs['tr'][] = $this->module->lang('err_missing_key', array($key)); } elseif ($lang2[$key] === $lang1[$key]) { $out = is_array($lang2[$key]) ? 'A(' . GWF_Array::implodeHuman($lang2[$key]) . ')' : $lang2[$key]; $warn['tr'][] = $this->module->lang('err_key_not_translated', array($key, htmlspecialchars($out))); } } if (isset($lang1[''])) { $errs['en'][] = $this->module->lang('err_not_finished', array($path1)); } } # Check if there really is a lang to check if (is_array($lang2)) { if (isset($lang2[''])) { $errs['tr'][] = $this->module->lang('err_not_finished', array($path2)); } # TODO: remove, do it faster # other-ISO lang file foreach ($lang2 as $key => $value) { if ($value === '') { $errs['tr'][] = $this->module->lang('err_empty_key', array($key)); } } } if ($lang2 !== false) { $this->errors['tr'] += count($errs['tr']); $this->warnings['tr'] += count($warn['tr']); $path = GWF_Debug::shortpath(realpath($path2)); # FIXME: duplication errors if two different modulelang locations if (count($errs['tr']) > 0) { $this->errErrorMessages[$path] = $errs['tr']; } if (count($warn['tr']) > 0 && $this->show_warns === true) { $this->errWarnMessages[$path] = $warn['tr']; } } if ($lang1 !== false) { $this->errors['en'] += count($errs['en']); $this->warnings['en'] += count($warn['en']); $path = GWF_Debug::shortpath(realpath($path1)); # FIXME: duplication errors if two different modulelang locations if (count($errs['en']) > 0) { $this->errErrorMessages[$path] = $errs['en']; } if (count($warn['en']) > 0 && $this->show_warns === true) { $this->errWarnMessages[$path] = $warn['en']; } } }
public static function displayMessages($messages) { if (count($messages) === 0) { return ''; } if (Common::getGet('ajax') !== false) { $output = ''; foreach ($messages['messages'] as $m) { $m2 = GWF_Debug::shortpath(self::decode($m)); $output .= sprintf('1:%d:%s', strlen($m2), $m2) . PHP_EOL; } return $output; // return GWF_Website::addDefaultOutput($output); } return GWF_Template::templateMain('message.tpl', array('title' => $messages['title'], 'messages' => $messages['messages'])); }
private static function displayAjax(&$subject) { $back = ''; foreach ($subject as $messages) { foreach ($messages as $msg) { $m = GWF_Debug::shortpath(self::decode($msg)); $back .= sprintf('0:%d:%s', strlen($m), $m) . PHP_EOL; } } GWF_Website::addDefaultOutput($back); return $back; }