diff options
author | Michal Čihař <michal@cihar.com> | 2012-04-06 12:53:45 +0400 |
---|---|---|
committer | Michal Čihař <michal@cihar.com> | 2012-04-06 12:53:45 +0400 |
commit | 88376c0385030e0af6954546721ccb7cd1b49956 (patch) | |
tree | 117a3a4521708e064d905a896f88325c81cfa7a3 /scripts | |
parent | 390d5ba4b7a8377b1e06d4fa5c874d2dab179796 (diff) |
Include real locations of advisory rules in po files
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/advisor2php | 60 | ||||
-rwxr-xr-x | scripts/update-po | 8 |
2 files changed, 53 insertions, 15 deletions
diff --git a/scripts/advisor2php b/scripts/advisor2php index 5c02237d40..4f39b639d2 100644 --- a/scripts/advisor2php +++ b/scripts/advisor2php @@ -5,6 +5,47 @@ * by gettext for generating po(t) files. */ +function format_string($str) { + return addcslashes(Advisor::escapePercent($str), '"\\'); +} + +$messages = array(); +$locations = array(); + +function add_message($rules, $idx, $type) { + global $messages, $locations; + // Get message text + if ($type == 'justification') { + $msg = Advisor::splitJustification($rules['rules'][$idx])[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; + } +} + +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"; +} + if (!file_exists('./libraries/Advisor.class.php')) { chdir('..'); } @@ -12,17 +53,14 @@ include './libraries/Advisor.class.php'; $rules = Advisor::parseRulesFile(); -echo "<?php\n"; -echo "/* DO NOT EDIT! */\n"; -echo "/* This is automatically generated file from libraries/advisory_rules.txt */\n"; - -foreach($rules['rules'] as $rule) { - echo "\n"; - echo "printf(__('" . addcslashes(Advisor::escapePercent($rule['name']), "'\\") . "'));\n"; - echo "printf(__('" . addcslashes(Advisor::escapePercent($rule['issue']), "'\\") . "'));\n"; - echo "printf(__('" . addcslashes(Advisor::escapePercent($rule['recommendation']), "'\\") . "'));\n"; - $jst = Advisor::splitJustification($rule); - echo "printf(__('" . addcslashes(Advisor::escapePercent($jst[0]), "'\\") . "'));\n"; +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); +} ?> diff --git a/scripts/update-po b/scripts/update-po index b0f99d465b..e387c87893 100755 --- a/scripts/update-po +++ b/scripts/update-po @@ -2,8 +2,6 @@ # vim: expandtab sw=4 ts=4 sts=4: export LC_ALL=C -# Generate PHP code for advisor rules -php ./scripts/advisor2php > po/advisory_rules.php # Update pot (template), ensure that advisor is at the end LOCS=`ls po/*.po | sed 's@.*/\(.*\)\.po@\1@'` @@ -17,8 +15,10 @@ xgettext \ --debug \ --keyword=__ --keyword=_pgettext:1c,2 --keyword=_ngettext:1,2 \ --copyright-holder="phpMyAdmin devel team" \ - `find . -name '*.php' -not -path './test/*' -not -path './po/*' | sort` \ - po/advisory_rules.php + `find . -name '*.php' -not -path './test/*' -not -path './po/*' | sort` + +# Generate PHP code for advisor rules +php ./scripts/advisor2php >> po/phpmyadmin.pot ver=`sed -n "/PMA_VERSION', '/ s/.*PMA_VERSION', '\(.*\)'.*/\1/p" libraries/Config.class.php` |