diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/extract2gettext.php | 19 | ||||
-rwxr-xr-x | tools/rebuild_gettext_catalogs.sh | 51 | ||||
-rw-r--r-- | tools/translated_converter.py | 43 |
3 files changed, 70 insertions, 43 deletions
diff --git a/tools/extract2gettext.php b/tools/extract2gettext.php index 0b1687540..424bb9172 100644 --- a/tools/extract2gettext.php +++ b/tools/extract2gettext.php @@ -54,8 +54,8 @@ $f = array(); $error = 0; if(count($out) == 0) { - echo "No strings to save from $php_source.\n"; - $error = 1; + if(!$quiet) { echo "No strings to save from $php_source.\n"; } + $error = 10; } foreach ($out as $str) { @@ -74,9 +74,10 @@ foreach ($out as $str) { } } else { - echo "\n\n!!!! Could not find string in $file, line $line: $str\n"; - echo "!!!! Please fix $file before using $domain.pot file!!!\n\n"; - $error = 2; + $parse_error = "\n\n!!!! Could not find string in $file, line $line: $str\n"; + $parse_error .= "!!!! Parse error, please fix $file before using $domain.pot file!!!\n\n"; + if(!$quiet) { echo $parse_error; } + $error = 20; } } @@ -121,13 +122,13 @@ foreach ($strings as $domain => $strs) { $dir = dirname($dest); if (!is_dir($dir)) { - echo "making $dir\n"; + if(!$quiet) { echo "making $dir\n"; } mkdir($dir, 0755, true); } - echo sprintf("saved %d strings in %s\n", count($strs), $dest); + if(!$quiet) { echo sprintf("saved %d strings in %s\n", count($strs), $dest); } if (FALSE === file_put_contents($dest, $f)) { - echo "Failed to write.\n"; - $error = 3; + if(!$quiet) { echo "Failed to write $f to $dest.\n"; } + $error = 30; } } if(!$quiet) { echo "Done. thxbye.\n"; } diff --git a/tools/rebuild_gettext_catalogs.sh b/tools/rebuild_gettext_catalogs.sh index 3b84f7974..011d4c4d8 100755 --- a/tools/rebuild_gettext_catalogs.sh +++ b/tools/rebuild_gettext_catalogs.sh @@ -7,26 +7,43 @@ error=0 declare -A resources +declare -A errors source ./tools/web_projects.dat for resource in "${!resources[@]}" do php_source=${resources[$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 + php_error_level=$? # catch php error level + error=$php_error_level + error_in_source=$php_source + errors[$php_source]=$php_sourc$php_error_level 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 + 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 + python tools/translated_converter.py --filename $directory/$resource + python_error_level=$? # catch python error level + if [ $python_error_level -gt 0 ]; then + error=50 + error_in_source=$directory/$resource + fi + fi + if [ -f $directory/$resource.po ]; then # update po file if it exists msgmerge --update --quiet $directory/$resource.po ./langs/en/$resource.pot + msgmerge_error_level=$? # catch msgmerge error level + if [ $msgmerge_error_level -gt 0 ]; then + error=60 + error_in_source=$directory/$resource + echo "$directory"/$resource.po could not be created succesfully + errors[$resource]=$resource$msgmerge_error_level + fi fi fi done @@ -34,8 +51,16 @@ do done echo '' -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 +#printf "%s\n" "${errors[@]}" +for error_in_source in "${!errors[@]}" +do + case ${errors[$error_in_source]} in + 0) echo "Done lookup for _g() and _r() in $error_in_source. Gettext catalogs (pot files) rebuilded. Existing po files updated." ;; + 1) echo "Unkown error!!" ;; + 10) echo "No strings to save from $error_in_source!" ;; + 20) echo "!!!! Parse error, please fix $error_in_source first !!!! See details above." ;; + 30) echo "!!!! Failed to write $error_in_source !!!! See details above." ;; + 50) echo "!!!! Script translated_converter.py encounter an error in $error_in_source !!!!" ;; + 60) echo "$error_in_source.po could not be created succesfully!!" ;; + esac +done diff --git a/tools/translated_converter.py b/tools/translated_converter.py index 219781636..2bdf61ceb 100644 --- a/tools/translated_converter.py +++ b/tools/translated_converter.py @@ -1,6 +1,15 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +# This file is free software. It come without any warranty, to the extent +# permitted by applicable law. You can redistribute it and/or modify them under +# the terms of the Do What The Fuck You Want To Public License, Version 2, as +# published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more details. + +# author yurchor +# http://gitweb.mageia.org/software/i18n/tools/tree/websites +# small adaptation by filip + import errno, glob, polib, re, os, getopt, sys from time import strftime @@ -8,34 +17,27 @@ def usage(): print '\nUsage: python %s [OPTION]' %os.path.basename(sys.argv[0]) print ' generates po file for existing lang translations' print 'Options: -h, --help : usage' - print ' -l lang_code, --language lang_code : code of the translation language' + print ' -f filename, --filename filename : target filename' sys.exit(2) try: - opts, args = getopt.getopt(sys.argv[1:], "hl:", ["help", "language="]) + opts, args = getopt.getopt(sys.argv[1:], "hf:", ["help", "filename="]) except getopt.GetoptError: usage() # print help information and exit -language='' +filename='' for o,a in opts: if o in ("-h", "--help"): usage() - if o in ("-l", "--language"): - lang_code=a + if o in ("-f", "--filename"): + filename=a -if lang_code == '': - sys.exit('Empty language code') +if filename == '': + sys.exit('No filename given') -file_extension = '.' + lang_code + '.lang' -file_mask = '*' + file_extension +file_mask = filename + '.*.lang' for langfile in glob.glob(file_mask): - langfilename = langfile.replace(file_extension, '') - # Create localization directories if needed - podir = langfilename + '/po' - try: - os.makedirs(podir) - except OSError, e: - if e.errno != errno.EEXIST: - raise + nofilename = langfile.replace(filename + '.','') + language = nofilename.replace('.lang','') #open lang file text = open(langfile,"r").read() #Remove trailing spaces from lines @@ -54,7 +56,8 @@ for langfile in glob.glob(file_mask): 'POT-Creation-Date': pocreationtime, 'PO-Revision-Date': pocreationtime, 'Last-Translator': 'Duffy Duck <d_duck@nowhere.net>', - 'Language-Team': lang_code + ' <mageia-' + lang_code + '@mageia.org>', + 'Language-Team': 'LANGUAGE <LL@li.org>', + 'Language': language, 'MIME-Version': '1.0', 'Content-Type': 'text/plain; charset=UTF-8', 'Content-Transfer-Encoding': '8bit', @@ -64,7 +67,6 @@ for langfile in glob.glob(file_mask): messagetemplate='\n\n#\ .*?\n\n' mpattern=re.compile(messagetemplate,re.DOTALL) for mblock in mpattern.findall(text): - mblock_stripped = mblock.strip('\n') message_comment, message_text = mblock.strip('\n').split('\n;',1) # Strip '# ' from comments message_comment = message_comment.lstrip('# ') @@ -100,5 +102,4 @@ for langfile in glob.glob(file_mask): occurrences=[(langfile,'')] ) po.append(potentry) - pofilename = langfilename + '/po/' + lang_code + '.po' - po.save(pofilename) + po.save(filename + '.po') |