forked from phpmyadmin/phpmyadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvisor2po
74 lines (65 loc) · 1.86 KB
/
advisor2po
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/* vim: set expandtab sw=4 ts=4 sts=4 ft=php: */
/**
* Script to parse advisor rules and output them as Gettext POT formatted
* strings for translation.
*/
$messages = array();
$locations = array();
/**
* Processes single advisor message and stores data in global array.
*/
function add_message($rules, $idx, $type) {
global $messages, $locations;
// Get message text
if ($type == 'justification') {
$msgs = Advisor::splitJustification($rules['rules'][$idx]);
$msg = $msgs[0];
} else {
$msg = $rules['rules'][$idx][$type];
}
$line = 'libraries/advisory_rules.txt:' . $rules['lines'][$idx][$type];
// Avoid duplicate mesages
$pos = array_search($msg, $messages);
if ($pos === false) {
$messages[] = $msg;
$locations[] = array($line);
} else {
$locations[$pos][] = $line;
}
}
/**
* Prints message at given location as Gettext string for translation.
*/
function print_message($idx) {
global $messages, $locations;
echo "\n";
echo '#: ' . implode(' ', $locations[$idx]);
echo "\n";
if (strstr($messages[$idx], '%') !== false) {
echo '#, php-format';
echo "\n";
}
echo 'msgid "' . addcslashes(Advisor::escapePercent($messages[$idx]), '"\\') . '"';
echo "\n";
echo 'msgstr ""';
echo "\n";
}
define('PHPMYADMIN', 1);
if (!file_exists('./libraries/Advisor.class.php')) {
chdir('..');
}
include './libraries/String.class.php';
$GLOBALS['PMA_String'] = new PMA_String();
include './libraries/Advisor.class.php';
$rules = Advisor::parseRulesFile();
foreach($rules['rules'] as $idx => $rule) {
add_message($rules, $idx, 'name');
add_message($rules, $idx, 'issue');
add_message($rules, $idx, 'recommendation');
add_message($rules, $idx, 'justification');
}
foreach($messages as $idx => $rule) {
print_message($idx);
}
?>