aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorFilip Komar <filip@mageia.org>2014-03-30 16:32:44 +0000
committerFilip Komar <filip@mageia.org>2014-03-30 16:32:44 +0000
commit3f8520d07e33b464f0b7555fd18387bd2d29ca4f (patch)
tree3e2591ab4b23875ce6cda7a6d8b016ed555f71a8 /tools
parentdc36c9fa5842f942e59848f34d6cb1d141be6ce2 (diff)
downloadwww-3f8520d07e33b464f0b7555fd18387bd2d29ca4f.tar
www-3f8520d07e33b464f0b7555fd18387bd2d29ca4f.tar.gz
www-3f8520d07e33b464f0b7555fd18387bd2d29ca4f.tar.bz2
www-3f8520d07e33b464f0b7555fd18387bd2d29ca4f.tar.xz
www-3f8520d07e33b464f0b7555fd18387bd2d29ca4f.zip
tools prepared for conversion of mognase to gettext
Diffstat (limited to 'tools')
-rw-r--r--tools/extract2gettext.php6
-rwxr-xr-xtools/rebuild_gettext_catalogs.sh119
-rw-r--r--tools/translated_converter.py11
3 files changed, 96 insertions, 40 deletions
diff --git a/tools/extract2gettext.php b/tools/extract2gettext.php
index a140195c3..ba2c927e9 100644
--- a/tools/extract2gettext.php
+++ b/tools/extract2gettext.php
@@ -119,7 +119,11 @@ foreach ($strings as $domain => $strs) {
$f[] = '';
}
$f = implode("\n", $f);
- $dest = sprintf('%s/langs/en/%s.pot', APP_ROOT, $domain);
+ if ($domain == 'mognase') {
+ $dest = sprintf('%s/_nav/langs/en.pot', APP_ROOT);
+ } else {
+ $dest = sprintf('%s/langs/en/%s.pot', APP_ROOT, $domain);
+ }
$dir = dirname($dest);
if (!is_dir($dir)) {
diff --git a/tools/rebuild_gettext_catalogs.sh b/tools/rebuild_gettext_catalogs.sh
index d32dfdde3..1c7b9e34e 100755
--- a/tools/rebuild_gettext_catalogs.sh
+++ b/tools/rebuild_gettext_catalogs.sh
@@ -17,73 +17,118 @@ fi
for resource in "${!resources[@]}"
do
difference=
- if [ -f ./langs/en/$resource.pot ]; then # do a temporary copy
- cp ./langs/en/$resource.pot ./langs/en/$resource.copy
+ if [ "$resource" = "mognase" ]; then # is it about navigation?
+ path_and_filename=./_nav/langs/en
+ else
+ path_and_filename=./langs/en/$resource
+ fi
+ if [ -f $path_and_filename.pot ]; then # do a temporary copy
+ cp $path_and_filename.pot $path_and_filename.copy
fi
php_source=${resources[$resource]}
php tools/extract2gettext.php "$php_source" $resource true
php_error_level=$? # catch php error level
errors[$php_source]=$php_error_level
- if [ -f ./langs/en/$resource.pot ]; then # msgmerge check of generated pot file
- msgmerge --quiet --no-wrap ./langs/en/$resource.pot ./langs/en/$resource.pot > ./langs/en/$resource.tmp
+ if [ -f $path_and_filename.pot ]; then
+ # msgmerge check of generated pot file
+ msgmerge --quiet --no-wrap $path_and_filename.pot $path_and_filename.pot --output-file=$path_and_filename.tmp
msgmerge_error_level=$? # catch msgmerge error level
if [ $msgmerge_error_level -gt 0 ]; then # on failure stop the process for this resource
errors[$php_source]=$msgmerge_error_level
- rm ./langs/en/$resource.tmp
+ rm $path_and_filename.tmp
fi
- if [ -f ./langs/en/$resource.copy ] && [ -f ./langs/en/$resource.tmp ]; then
- diff --ignore-matching-lines='^"POT-Creation-Date:' ./langs/en/$resource.tmp ./langs/en/$resource.copy
+ if [ -f $path_and_filename.copy ] && [ -f $path_and_filename.tmp ]; then
+ diff --ignore-matching-lines='^"POT-Creation-Date:' $path_and_filename.tmp $path_and_filename.copy
if [ $? -eq 1 ]; then # there are differences
errors[$php_source]=0
- mv ./langs/en/$resource.tmp ./langs/en/$resource.pot
- rm ./langs/en/$resource.copy
- echo Changes in ./langs/en/$resource.pot
+ mv $path_and_filename.tmp $path_and_filename.pot
+ rm $path_and_filename.copy
+ echo Changes in $path_and_filename.pot
else # Cleanup as there are no changes in $resource
errors[$php_source]=5
- rm ./langs/en/$resource.tmp
- mv ./langs/en/$resource.copy ./langs/en/$resource.pot
+ rm $path_and_filename.tmp
+ mv $path_and_filename.copy $path_and_filename.pot
difference=none
fi
else # diff not possible
- if [ -f ./langs/en/$resource.tmp ]; then
- mv ./langs/en/$resource.tmp ./langs/en/$resource.pot
- rm ./langs/en/$resource.copy
+ if [ -f $path_and_filename.tmp ]; then
+ mv $path_and_filename.tmp $path_and_filename.pot
+ if [ -f $path_and_filename.copy ]; then
+ rm $path_and_filename.copy
+ fi
else
- rm ./langs/en/$resource.pot
- if [ -f ./langs/en/$resource.copy ]; then
- mv ./langs/en/$resource.copy ./langs/en/$resource.pot
+ rm $path_and_filename.pot
+ if [ -f $path_and_filename.copy ]; then
+ mv $path_and_filename.copy $path_and_filename.pot
difference=none
fi
fi
fi
- for directory in ./langs/*
- do
- # in each language directory except source
- if [ -d $directory/ ] && [ $directory != ./langs/en ]; then
- # create po file if needed from lang file if available
- if [ ! -f $directory/$resource.po ] && [ -f $directory/$resource.*.lang ]; then
-# echo $directory # usefull for debuging of non UTF-8 files or other python errors
- python tools/translated_converter.py --filename $directory/$resource
- python_error_level=$? # catch python error level
- if [ $python_error_level -gt 0 ]; then
- errors[$directory/$resource]=50
- fi
+ if [ "$resource" = "mognase" ]; then # is it about navigation?
+ # create po files if needed from lang files if available
+ if [ -f ./_nav/langs/en.lang ]; then
+ python tools/translated_converter.py --filename ./_nav/langs/
+ python_error_level=$? # catch python error level
+ if [ $python_error_level -gt 0 ]; then
+ errors[$resource]=50
fi
- if [ -f $directory/$resource.po ] && [ -z $difference ]; then # update po file if it exists
-# msgfmt --statistics --verbose -c $directory/$resource.po -o /dev/null # usefull for debuging (msgctxt "/web/en/ or msgctxt "en/)
- echo merging $directory/$resource.po
- msgmerge --quiet --no-wrap $directory/$resource.po ./langs/en/$resource.pot > $directory/$resource.tmp
+ if [ -f ./_nav/langs/en.po ]; then
+ rm ./_nav/langs/en.po
+ fi
+ fi
+
+ for tr_file in ./_nav/langs/*.po
+ do
+ if [ -z $difference ]; then # update po file if needed
+# msgfmt --statistics --verbose -c $tr_file -o /dev/null # usefull for debuging (msgctxt "/web/en/ or msgctxt "en/)
+ echo merging $tr_file
+ msgmerge --quiet --no-wrap $tr_file ./_nav/langs/en.pot --output-file=$tr_file.tmp
msgmerge_error_level=$? # catch msgmerge error level
if [ $msgmerge_error_level -gt 0 ]; then
errors[$directory/$resource]=60
echo "$directory"/$resource.po could not be created succesfully
+ if [ -f $tr_file.tmp ]; then
+ rm $tr_file.tmp
+ fi
else
- mv $directory/$resource.tmp $directory/$resource.po
+ mv $tr_file.tmp $tr_file
+# msgfmt --statistics --verbose -c $tr_file -o /dev/null # usefull for debuging (msgctxt "/web/en/ or msgctxt "en/)
+ fi
+ fi
+ done
+ else
+ for directory in ./langs/*
+ do
+ # in each language directory except source
+ if [ -d $directory/ ] && [ $directory != ./langs/en ]; then
+ # create po file if needed from lang file if available
+ if [ ! -f $directory/$resource.po ] && [ -f $directory/$resource.*.lang ]; then
+# echo $directory # usefull for debuging of non UTF-8 files or other python errors
+ python tools/translated_converter.py --filename $directory/$resource
+ python_error_level=$? # catch python error level
+ if [ $python_error_level -gt 0 ]; then
+ errors[$directory/$resource]=50
+ fi
+ fi
+ if [ -f $directory/$resource.po ] && [ -z $difference ]; then # update po file if it exists
# msgfmt --statistics --verbose -c $directory/$resource.po -o /dev/null # usefull for debuging (msgctxt "/web/en/ or msgctxt "en/)
+ echo merging $directory/$resource.po
+ msgmerge --quiet --no-wrap $directory/$resource.po ./langs/en/$resource.pot --output-file=$directory/$resource.tmp
+ msgmerge_error_level=$? # catch msgmerge error level
+ if [ $msgmerge_error_level -gt 0 ]; then
+ errors[$directory/$resource]=60
+ echo "$directory"/$resource.po could not be created succesfully
+ if [ -f $tr_file.tmp ]; then
+ rm $directory/$resource.tmp
+ fi
+ else
+ mv $directory/$resource.tmp $directory/$resource.po
+# msgfmt --statistics --verbose -c $directory/$resource.po -o /dev/null # usefull for debuging (msgctxt "/web/en/ or msgctxt "en/)
+ fi
fi
fi
- fi
- done
+ done
+ fi
fi
done
diff --git a/tools/translated_converter.py b/tools/translated_converter.py
index 76fcd9cd6..568e3fb43 100644
--- a/tools/translated_converter.py
+++ b/tools/translated_converter.py
@@ -8,7 +8,7 @@
# author yurchor
# http://gitweb.mageia.org/software/i18n/tools/tree/websites
-# small adaptation by filip
+# adaptation by filip
import errno, glob, polib, re, os, getopt, sys
from time import strftime
@@ -48,10 +48,13 @@ def po_append(message_id, message_str, langfile):
po.append(potentry)
file_mask = filename + '.*.lang'
+if filename == './_nav/langs/':
+ file_mask = './_nav/langs/*.lang'
for langfile in glob.glob(file_mask):
# print langfile # useful for debuging
nofilename = langfile.replace(filename + '.','')
language = nofilename.replace('.lang','')
+ language = language.replace('./_nav/langs/','')
#open lang file
text = open(langfile,"r").read()+"\n"
#Remove trailing spaces from lines
@@ -97,4 +100,8 @@ for langfile in glob.glob(file_mask):
message_id, message_str = text.partition('\n\n')[0].strip('\n').split('\n',1)
# print message_id # useful for debuging
po_append(message_id, message_str, langfile)
- po.save(filename + '.po')
+ if filename == './_nav/langs/':
+ file_name = filename + language
+ else:
+ file_name = filename
+ po.save(file_name + '.po')