check_languages.py now compares _all_ files of a given language with the english one
This commit is contained in:
parent
0eeeda7036
commit
4df227a99d
1 changed files with 60 additions and 36 deletions
|
@ -2,16 +2,15 @@
|
||||||
#
|
#
|
||||||
# $Id$
|
# $Id$
|
||||||
#
|
#
|
||||||
# compare a translated language file with the master (english) language file
|
# compare translated language files with the master (english) language files
|
||||||
# it is useful for finding incomplete translation
|
# it is useful for finding incomplete translations
|
||||||
#
|
#
|
||||||
# Copyright (c) 02006 sense.lab <senselab@systemausfall.org>
|
# Copyright (c) 02006 sense.lab <senselab@systemausfall.org>
|
||||||
#
|
#
|
||||||
# License: This script is distributed under the terms of version 2
|
# License: This script is distributed under the terms of version 2
|
||||||
# of the GNU GPL. See the LICENSE file included with the package.
|
# of the GNU GPL. See the LICENSE file included with the package.
|
||||||
#
|
#
|
||||||
# Parameter: LANGUAGE_FILE
|
# Parameter: LANGUAGE (e.g. "de")
|
||||||
# (e.g. "lang/de.hdf")
|
|
||||||
#
|
#
|
||||||
|
|
||||||
import os, sys
|
import os, sys
|
||||||
|
@ -32,6 +31,53 @@ def getHDFkeys(hdf):
|
||||||
return [e.split(" = ",1)[0].strip() for e in hdf.dump().splitlines()]
|
return [e.split(" = ",1)[0].strip() for e in hdf.dump().splitlines()]
|
||||||
|
|
||||||
|
|
||||||
|
def compareFiles(langFile1, langFile2):
|
||||||
|
## 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)
|
||||||
|
return
|
||||||
|
|
||||||
|
## check if the files are the same
|
||||||
|
if langFile1 == langFile2:
|
||||||
|
sys.stderr.write("cannot compare the language file with itself: %s\n" % langFile1)
|
||||||
|
return
|
||||||
|
|
||||||
|
print "Comparing '%s' and '%s':" % (langFile1, langFile2)
|
||||||
|
|
||||||
|
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("\tthe language file is empty: %s\n" % filename)
|
||||||
|
return
|
||||||
|
|
||||||
|
## check for missing keys (only part of the first (master) file)
|
||||||
|
for key in hdfKeys1:
|
||||||
|
if not key in hdfKeys2:
|
||||||
|
print "\tmissing key: %s" % key
|
||||||
|
|
||||||
|
## check for superfluous keys (only part of the second file)
|
||||||
|
for key in hdfKeys2:
|
||||||
|
if not key in hdfKeys1:
|
||||||
|
print "\tsuperfluous key: %s" % key
|
||||||
|
|
||||||
|
|
||||||
|
def find_lang_file(arg, dirname, fnames):
|
||||||
|
lfile = os.path.join(dirname, arg["fname"])
|
||||||
|
if os.path.isfile(lfile):
|
||||||
|
arg["list"].append(lfile)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
############ main #############
|
||||||
if "__main__" != __name__:
|
if "__main__" != __name__:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
@ -39,44 +85,22 @@ args = sys.argv[1:]
|
||||||
|
|
||||||
## check parameters
|
## check parameters
|
||||||
if len(args) != 1:
|
if len(args) != 1:
|
||||||
sys.stderr.write("invalid number of parameters: a language file is required\n")
|
sys.stderr.write("invalid number of parameters: a language name is required\n")
|
||||||
sys.exit(1)
|
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
|
language = args[0]
|
||||||
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 language == DEFAULT_LANGUAGE:
|
||||||
if langFile1 == langFile2:
|
sys.stderr.write("you must specify a language different from the default (%s)!\n" % DEFAULT_LANGUAGE)
|
||||||
sys.stderr.write("cannot compare the language file with itself: %s\n" % langFile1)
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
hdf1 = neo_util.HDF()
|
obj = { "fname":"%s%s" % (DEFAULT_LANGUAGE, SUFFIX),
|
||||||
hdf1.readFile(langFile1)
|
"list": [] }
|
||||||
hdf2 = neo_util.HDF()
|
|
||||||
hdf2.readFile(langFile2)
|
|
||||||
|
|
||||||
hdfKeys1 = getHDFkeys(hdf1)
|
os.path.walk(os.getcwd(), find_lang_file, obj)
|
||||||
hdfKeys2 = getHDFkeys(hdf2)
|
|
||||||
|
|
||||||
## check for empty language data sets
|
for langFile in obj["list"]:
|
||||||
for (keys, filename) in ((hdfKeys1, langFile1), (hdfKeys2, langFile2)):
|
refLang = langFile.replace("/%s%s" % (DEFAULT_LANGUAGE, SUFFIX), "/%s%s" % (language, SUFFIX))
|
||||||
if len(keys) == 0:
|
compareFiles(refLang, langFile)
|
||||||
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
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue