replaced the old bash script for translation checks by a better (and longer) python script
This commit is contained in:
parent
e238cbd17e
commit
52ccaeb530
2 changed files with 82 additions and 26 deletions
82
pythonrewrite/scripts/check_languages.py
Executable file
82
pythonrewrite/scripts/check_languages.py
Executable file
|
@ -0,0 +1,82 @@
|
|||
#!/usr/bin/env python2.4
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# compare a translated language file with the master (english) language file
|
||||
# it is useful for finding incomplete translation
|
||||
#
|
||||
# Copyright (c) 02006 sense.lab <senselab@systemausfall.org>
|
||||
#
|
||||
# License: This script is distributed under the terms of version 2
|
||||
# of the GNU GPL. See the LICENSE file included with the package.
|
||||
#
|
||||
# Parameter: LANGUAGE_FILE
|
||||
# (e.g. "lang/de.hdf")
|
||||
#
|
||||
|
||||
import os, sys
|
||||
try:
|
||||
import neo_cgi, neo_util
|
||||
except ImportError, errMsg:
|
||||
sys.stderr.write("Could not import the python clearsilver module: %s\n" % (errMsg,))
|
||||
sys.stderr.write("Maybe you should try 'apt-get install python-clearsilver'?\n")
|
||||
sys.exit(1)
|
||||
|
||||
SUFFIX = ".hdf"
|
||||
DEFAULT_LANGUAGE = "en"
|
||||
|
||||
|
||||
def getHDFkeys(hdf):
|
||||
import types
|
||||
if type(hdf.dump()) == types.NoneType: return []
|
||||
return [e.split(" = ",1)[0].strip() for e in hdf.dump().splitlines()]
|
||||
|
||||
|
||||
if "__main__" != __name__:
|
||||
sys.exit(0)
|
||||
|
||||
args = sys.argv[1:]
|
||||
|
||||
## check parameters
|
||||
if len(args) != 1:
|
||||
sys.stderr.write("invalid number of parameters: a language file is required\n")
|
||||
sys.exit(1)
|
||||
|
||||
langFile2 = os.path.abspath(args[0])
|
||||
langFile1 = os.path.join(os.path.dirname(langFile2), DEFAULT_LANGUAGE + SUFFIX)
|
||||
|
||||
## check for existence of files
|
||||
for filename in (langFile2, langFile1):
|
||||
if not os.path.exists(filename):
|
||||
sys.stderr.write("could not find language file: %s\n" % filename)
|
||||
sys.exit(1)
|
||||
|
||||
## check if the files are the same
|
||||
if langFile1 == langFile2:
|
||||
sys.stderr.write("cannot compare the language file with itself: %s\n" % langFile1)
|
||||
sys.exit(1)
|
||||
|
||||
hdf1 = neo_util.HDF()
|
||||
hdf1.readFile(langFile1)
|
||||
hdf2 = neo_util.HDF()
|
||||
hdf2.readFile(langFile2)
|
||||
|
||||
hdfKeys1 = getHDFkeys(hdf1)
|
||||
hdfKeys2 = getHDFkeys(hdf2)
|
||||
|
||||
## check for empty language data sets
|
||||
for (keys, filename) in ((hdfKeys1, langFile1), (hdfKeys2, langFile2)):
|
||||
if len(keys) == 0:
|
||||
sys.stderr.write("the language file is empty: %s\n" % filename)
|
||||
sys.exit(1)
|
||||
|
||||
## check for missing keys (only part of the first (master) file)
|
||||
for key in hdfKeys1:
|
||||
if not key in hdfKeys2:
|
||||
print "missing key: %s" % key
|
||||
|
||||
## check for superfluous keys (only part of the second file)
|
||||
for key in hdfKeys2:
|
||||
if not key in hdfKeys1:
|
||||
print "superfluous key: %s" % key
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# compare the defined fields of a language file with the english translation
|
||||
#
|
||||
# nice for finding unavailable definitions
|
||||
#
|
||||
# Parameter: LANGUAGE
|
||||
# (e.g. "de")
|
||||
#
|
||||
|
||||
set -u
|
||||
|
||||
LANG_DIR=$(dirname $0)/../lang
|
||||
DEFAULT_LANG=en
|
||||
TMP_FILE1=/tmp/$(basename $0)-$$-1
|
||||
TMP_FILE2=/tmp/$(basename $0)-$$-2
|
||||
|
||||
[ $# -ne 1 ] && echo -e "Syntax: $(basename $0) LANGUAGE\n" >&2 && exit 1
|
||||
|
||||
grep "=" "$LANG_DIR/${DEFAULT_LANG}.hdf" | grep -v "^[[:space:]]*#" | cut -f 1 -d "=" >"$TMP_FILE1"
|
||||
grep "=" "$LANG_DIR/${1}.hdf" | grep -v "^[[:space:]]*#" | cut -f 1 -d "=" >"$TMP_FILE2"
|
||||
|
||||
diff -wu "$TMP_FILE1" "$TMP_FILE2"
|
||||
|
||||
rm "$TMP_FILE1" "$TMP_FILE2"
|
||||
|
Loading…
Reference in a new issue