cryptonas-branches/pythonrewrite/scripts/check_languages.py

82 lines
2.1 KiB
Python
Executable file

#!/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