2009-06-13 16:54:04 +00:00
|
|
|
import sys, os
|
|
|
|
|
2010-10-13 10:58:25 +00:00
|
|
|
source_exts = [".c", ".cpp", ".h"]
|
2009-06-13 16:54:04 +00:00
|
|
|
|
|
|
|
def parse_source():
|
|
|
|
stringtable = {}
|
|
|
|
def process_line(line):
|
2010-10-13 10:58:25 +00:00
|
|
|
if 'Localize("' in line:
|
|
|
|
fields = line.split('Localize("', 1)[1].split('"', 1)
|
2009-06-13 16:54:04 +00:00
|
|
|
stringtable[fields[0]] = ""
|
|
|
|
process_line(fields[1])
|
|
|
|
|
2010-10-13 10:58:25 +00:00
|
|
|
for root, dirs, files in os.walk("../src"):
|
2009-06-13 16:54:04 +00:00
|
|
|
for name in files:
|
|
|
|
filename = os.path.join(root, name)
|
|
|
|
|
|
|
|
if os.sep + "external" + os.sep in filename:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if filename[-2:] in source_exts or filename[-4:] in source_exts:
|
2010-10-13 10:58:25 +00:00
|
|
|
for line in open(filename, "rb"):
|
2009-06-13 16:54:04 +00:00
|
|
|
process_line(line)
|
|
|
|
|
|
|
|
return stringtable
|
|
|
|
|
|
|
|
def load_languagefile(filename):
|
2010-10-13 10:58:25 +00:00
|
|
|
f = open(filename, "rb")
|
2009-06-13 16:54:04 +00:00
|
|
|
lines = f.readlines()
|
|
|
|
f.close()
|
2010-10-13 10:58:25 +00:00
|
|
|
|
2009-06-13 16:54:04 +00:00
|
|
|
stringtable = {}
|
|
|
|
|
2010-11-20 23:48:47 +00:00
|
|
|
for i in range(0, len(lines)-1):
|
2010-10-13 10:58:25 +00:00
|
|
|
l = lines[i].decode("utf-8").strip()
|
2009-06-13 16:54:04 +00:00
|
|
|
if len(l) and not l[0] == '=' and not l[0] == '#':
|
2010-11-20 23:48:47 +00:00
|
|
|
stringtable[l] = lines[i+1][3:].decode("utf-8").rstrip()
|
2010-10-13 10:58:25 +00:00
|
|
|
|
2009-06-13 16:54:04 +00:00
|
|
|
return stringtable
|
|
|
|
|
|
|
|
def generate_languagefile(outputfilename, srctable, loctable):
|
2010-10-13 10:58:25 +00:00
|
|
|
f = open(outputfilename, "wb")
|
2009-06-13 16:54:04 +00:00
|
|
|
|
|
|
|
num_items = 0
|
|
|
|
new_items = 0
|
|
|
|
old_items = 0
|
|
|
|
|
2010-10-13 10:58:25 +00:00
|
|
|
srctable_keys = []
|
|
|
|
for key in srctable:
|
|
|
|
srctable_keys.append(key)
|
2009-06-15 07:34:25 +00:00
|
|
|
srctable_keys.sort()
|
|
|
|
|
2010-10-13 10:58:25 +00:00
|
|
|
content = "\n##### translated strings #####\n\n"
|
2009-06-15 07:34:25 +00:00
|
|
|
for k in srctable_keys:
|
2009-06-13 17:18:06 +00:00
|
|
|
if k in loctable and len(loctable[k]):
|
2010-11-20 23:48:47 +00:00
|
|
|
content += "%s\n== %s\n\n" % (k, loctable[k])
|
2009-06-13 16:54:04 +00:00
|
|
|
num_items += 1
|
|
|
|
|
|
|
|
|
2010-10-13 10:58:25 +00:00
|
|
|
content += "##### needs translation #####\n\n"
|
2009-06-15 07:34:25 +00:00
|
|
|
for k in srctable_keys:
|
2009-06-13 17:18:06 +00:00
|
|
|
if not k in loctable or len(loctable[k]) == 0:
|
2010-11-20 23:48:47 +00:00
|
|
|
content += "%s\n== \n\n" % (k)
|
2009-06-13 16:54:04 +00:00
|
|
|
num_items += 1
|
|
|
|
new_items += 1
|
|
|
|
|
2010-10-13 10:58:25 +00:00
|
|
|
content += "##### old translations #####\n\n"
|
2009-06-13 16:54:04 +00:00
|
|
|
for k in loctable:
|
|
|
|
if not k in srctable:
|
2010-11-20 23:48:47 +00:00
|
|
|
content += "%s\n== %s\n\n" % (k, loctable[k])
|
2009-06-13 16:54:04 +00:00
|
|
|
num_items += 1
|
|
|
|
old_items += 1
|
2009-06-15 07:34:25 +00:00
|
|
|
|
2010-10-13 10:58:25 +00:00
|
|
|
f.write(content.encode("utf-8"))
|
|
|
|
f.close()
|
|
|
|
print("%-40s %8d %8d %8d" % (outputfilename, num_items, new_items, old_items))
|
2009-06-13 16:54:04 +00:00
|
|
|
|
|
|
|
srctable = parse_source()
|
|
|
|
|
2010-10-13 10:58:25 +00:00
|
|
|
print("%-40s %8s %8s %8s" % ("filename", "total", "new", "old"))
|
2009-06-15 09:46:25 +00:00
|
|
|
|
2010-10-13 10:58:25 +00:00
|
|
|
for filename in os.listdir("../data/languages"):
|
2009-06-13 16:54:04 +00:00
|
|
|
if not ".txt" in filename:
|
|
|
|
continue
|
2010-10-13 10:58:25 +00:00
|
|
|
if filename == "index.txt":
|
|
|
|
continue
|
2009-06-13 16:54:04 +00:00
|
|
|
|
2010-10-13 10:58:25 +00:00
|
|
|
filename = "../data/languages/" + filename
|
2009-06-13 16:54:04 +00:00
|
|
|
generate_languagefile(filename, srctable, load_languagefile(filename))
|