aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorFilip Komar <filip@mageia.org>2014-03-02 15:14:50 +0000
committerFilip Komar <filip@mageia.org>2014-03-02 15:14:50 +0000
commit29e810a98cc8aafdf27cc5b83530050b4d4a397b (patch)
tree1a0dcb1715fea50c8ed44e255948f4bb9b2e44ef /tools
parentae76140d7467053ed646054daaec09ebbade7d03 (diff)
downloadwww-29e810a98cc8aafdf27cc5b83530050b4d4a397b.tar
www-29e810a98cc8aafdf27cc5b83530050b4d4a397b.tar.gz
www-29e810a98cc8aafdf27cc5b83530050b4d4a397b.tar.bz2
www-29e810a98cc8aafdf27cc5b83530050b4d4a397b.tar.xz
www-29e810a98cc8aafdf27cc5b83530050b4d4a397b.zip
added rebuilding existing po files + some error managament + verbosity improvements
Diffstat (limited to 'tools')
-rw-r--r--tools/extract2gettext.php16
-rwxr-xr-xtools/rebuild_gettext_catalogs.sh29
2 files changed, 38 insertions, 7 deletions
diff --git a/tools/extract2gettext.php b/tools/extract2gettext.php
index 559285573..0b1687540 100644
--- a/tools/extract2gettext.php
+++ b/tools/extract2gettext.php
@@ -24,6 +24,7 @@ define('APP_ROOT', realpath(__DIR__ . '/..'));
$php_source = isset($argv[1]) ? $argv[1] : null;
$domain = isset($argv[2]) ? $argv[2] : null;
+$quiet = isset($argv[3]) ? $argv[3] : false;
if (is_null($php_source) || is_null($domain)) {
echo <<<U
@@ -42,16 +43,21 @@ U;
date_default_timezone_set(@date_default_timezone_get());
-echo "ohay!\n";
+if(!$quiet) { echo "ohay!\n";}
$cmd = sprintf('grep -HrnEi "_(g|r)\((.*)" %s', $php_source);
-//echo $cmd, "\n";
+if(!$quiet) { echo $cmd, "\n"; }
exec($cmd, $out);
$strings = array();
$f = array();
$error = 0;
+if(count($out) == 0) {
+ echo "No strings to save from $php_source.\n";
+ $error = 1;
+}
+
foreach ($out as $str) {
$arr = explode(':', $str);
$file = array_shift($arr);
@@ -119,8 +125,10 @@ foreach ($strings as $domain => $strs) {
mkdir($dir, 0755, true);
}
echo sprintf("saved %d strings in %s\n", count($strs), $dest);
- if (FALSE === file_put_contents($dest, $f))
+ if (FALSE === file_put_contents($dest, $f)) {
echo "Failed to write.\n";
+ $error = 3;
+ }
}
-echo "Done. thxbye.\n";
+if(!$quiet) { echo "Done. thxbye.\n"; }
exit($error);
diff --git a/tools/rebuild_gettext_catalogs.sh b/tools/rebuild_gettext_catalogs.sh
index 55c4908fd..3b84f7974 100755
--- a/tools/rebuild_gettext_catalogs.sh
+++ b/tools/rebuild_gettext_catalogs.sh
@@ -5,14 +5,37 @@
# @copyright 2014/03
# inspired by check_for_translation_work.sh
+error=0
declare -A resources
-
source ./tools/web_projects.dat
for resource in "${!resources[@]}"
do
php_source=${resources[$resource]}
- php tools/extract2gettext.php $php_source $resource
+ php tools/extract2gettext.php $php_source $resource true
+ current_error_level=$? # catch error level
+ if [ $current_error_level -gt 1 ]; then
+ error=$current_error_level
+ error_in_source=$php_source
+ fi
+ if [ -f ./langs/en/$resource.pot ]; then # cut too long lines
+ msgmerge --quiet ./langs/en/$resource.pot ./langs/en/$resource.pot > ./langs/en/$resource.tmp
+ mv ./langs/en/$resource.tmp ./langs/en/$resource.pot
+
+ for directory in ./langs/*
+ do # update po files too
+ if [ -d $directory/ ]; then
+ if [ -f $directory/$resource.po ]; then
+ msgmerge --update --quiet $directory/$resource.po ./langs/en/$resource.pot
+ fi
+ fi
+ done
+ fi
done
+
echo ''
-echo "Done lookup for _g() and _r() in php source code and build a gettext catalog (pot file)"
+case $error in
+ 0) echo "Done lookup for _g() and _r() in php source code. Gettext catalogs (pot files) rebuilded. Existing po files updated." ;;
+ 2) echo "!!!! Please fix $error_in_source first !!!! See details above." ;;
+ 3) echo "!!!! Failed to write $error_in_source !!!! See details above." ;;
+esac