Refactored ConfigFile class so that it is no longer a singleton
[phpmyadmin.git] / scripts / advisor2po
blob7c0e1805e095d258c7571db2e4e1ac2b4db41cc1
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4 ft=php: */
3 /**
4  * Script to parse advisor rules and output them as Gettext POT formatted
5  * strings for translation.
6  */
8 $messages = array();
9 $locations = array();
11 /**
12  * Processes single advisor message and stores data in global array.
13  */
14 function add_message($rules, $idx, $type) {
15     global $messages, $locations;
16     // Get message text
17     if ($type == 'justification') {
18         $msgs = Advisor::splitJustification($rules['rules'][$idx]);
19         $msg = $msgs[0];
20     } else {
21         $msg = $rules['rules'][$idx][$type];
22     }
23     $line = 'libraries/advisory_rules.txt:' . $rules['lines'][$idx][$type];
24     // Avoid duplicate mesages
25     $pos = array_search($msg, $messages);
26     if ($pos === false) {
27         $messages[] = $msg;
28         $locations[] = array($line);
29     } else {
30         $locations[$pos][] = $line;
31     }
34 /**
35  * Prints message at given location as Gettext string for translation.
36  */
37 function print_message($idx) {
38     global $messages, $locations;
39     echo "\n";
40     echo '#: ' . implode(' ', $locations[$idx]);
41     echo "\n";
42     if (strstr($messages[$idx], '%') !== false) {
43         echo '#, php-format';
44         echo "\n";
45     }
46     echo 'msgid "' . addcslashes(Advisor::escapePercent($messages[$idx]), '"\\') . '"';
47     echo "\n";
48     echo 'msgstr ""';
49     echo "\n";
52 define('PHPMYADMIN', 1);
53 if (!file_exists('./libraries/Advisor.class.php')) {
54     chdir('..');
56 include './libraries/Advisor.class.php';
58 $rules = Advisor::parseRulesFile();
60 foreach($rules['rules'] as $idx => $rule) {
61     add_message($rules, $idx, 'name');
62     add_message($rules, $idx, 'issue');
63     add_message($rules, $idx, 'recommendation');
64     add_message($rules, $idx, 'justification');
67 foreach($messages as $idx => $rule) {
68     print_message($idx);