2 /* vim: set expandtab sw=4 ts=4 sts=4 ft=php: */
4 * Script to parse advisor rules and output them as PHP code which can be used
5 * by gettext for generating po(t) files.
8 function format_string($str) {
9 return addcslashes(Advisor::escapePercent($str), '"\\');
15 function add_message($rules, $idx, $type) {
16 global $messages, $locations;
18 if ($type == 'justification') {
19 $msgs = Advisor::splitJustification($rules['rules'][$idx]);
22 $msg = $rules['rules'][$idx][$type];
24 $line = 'libraries/advisory_rules.txt:' . $rules['lines'][$idx][$type];
25 // Avoid duplicate mesages
26 $pos = array_search($msg, $messages);
29 $locations[] = array($line);
31 $locations[$pos][] = $line;
35 function print_message($idx) {
36 global $messages, $locations;
38 echo '#: ' . implode(' ', $locations[$idx]);
40 if (strstr($messages[$idx], '%') !== false) {
44 echo 'msgid "' . addcslashes(Advisor::escapePercent($messages[$idx]), '"\\') . '"';
50 define('PHPMYADMIN', 1);
51 if (!file_exists('./libraries/Advisor.class.php')) {
54 include './libraries/Advisor.class.php';
56 $rules = Advisor::parseRulesFile();
58 foreach($rules['rules'] as $idx => $rule) {
59 add_message($rules, $idx, 'name');
60 add_message($rules, $idx, 'issue');
61 add_message($rules, $idx, 'recommendation');
62 add_message($rules, $idx, 'justification');
65 foreach($messages as $idx => $rule) {