about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChoupom <andycootlapin@hotmail.fr>2010-10-13 12:58:25 +0200
committeroy <Tom_Adams@web.de>2010-11-21 00:28:13 +0100
commit7ad1d6080567c2507ee0bd83630f3ddf19aae95c (patch)
tree24d817b343b1cb50df13256b954c43d99e44a5ee
parente447de38ba81aabc04d8157015b2607d38040e74 (diff)
downloadzcatch-7ad1d6080567c2507ee0bd83630f3ddf19aae95c.tar.gz
zcatch-7ad1d6080567c2507ee0bd83630f3ddf19aae95c.zip
updated update_localization.py by Sworddragon
-rw-r--r--scripts/update_localization.py100
1 files changed, 60 insertions, 40 deletions
diff --git a/scripts/update_localization.py b/scripts/update_localization.py
index a1e19b8b..5c764bc9 100644
--- a/scripts/update_localization.py
+++ b/scripts/update_localization.py
@@ -1,16 +1,44 @@
 import sys, os
 
-source_exts = [".c", ".cpp", ".h", ".hpp"]
+
+
+def _import(library):
+	if sys.version_info[0] == 2:
+		return library[0]
+	if sys.version_info[0] == 3:
+		return library[1]
+
+def _input(output):
+	if sys.version_info[0] == 2:
+		raw_input(output)
+	if sys.version_info[0] == 3:
+		input(output)
+
+def _ord(character):
+	if sys.version_info[0] == 2:
+		return ord(character)
+	if sys.version_info[0] == 3:
+		return character
+
+def _xrange(start = 0, stop = 0, step = 1):
+	if sys.version_info[0] == 2:
+		return xrange(start, stop, step)
+	if sys.version_info[0] == 3:
+		return range(start, stop, step)
+
+
+
+source_exts = [".c", ".cpp", ".h"]
 
 def parse_source():
 	stringtable = {}
 	def process_line(line):
-		if 'localize("' in line:
-			fields = line.split('localize("', 2)[1].split('"', 2)
+		if 'Localize("' in line:
+			fields = line.split('Localize("', 1)[1].split('"', 1)
 			stringtable[fields[0]] = ""
 			process_line(fields[1])
 
-	for root, dirs, files in os.walk("src"):
+	for root, dirs, files in os.walk("../src"):
 		for name in files:
 			filename = os.path.join(root, name)
 			
@@ -18,82 +46,74 @@ def parse_source():
 				continue
 			
 			if filename[-2:] in source_exts or filename[-4:] in source_exts:
-				for line in file(filename):
+				for line in open(filename, "rb"):
 					process_line(line)
 	
 	return stringtable
 
 def load_languagefile(filename):
-	f = file(filename)
+	f = open(filename, "rb")
 	lines = f.readlines()
 	f.close()
+	
 	stringtable = {}
 
-	for i in xrange(0, len(lines)-1):
-		l = lines[i].strip()
+	for i in _xrange(0, len(lines)-1):
+		l = lines[i].decode("utf-8").strip()
+		if len(l) and l[0] == '#' and "needs translation" in l:
+			break
 		if len(l) and not l[0] == '=' and not l[0] == '#':
-			stringtable[l] = lines[i+1][3:].strip()
-			
+			stringtable[l] = lines[i+1][2:].decode("utf-8").rstrip()
+	
 	return stringtable
 
-
 def generate_languagefile(outputfilename, srctable, loctable):
-	tmpfilename = outputfilename[:-1]+"_"
-	f = file(tmpfilename, "w")
+	f = open(outputfilename, "wb")
 
 	num_items = 0
 	new_items = 0
 	old_items = 0
 
-	srctable_keys = srctable.keys()
+	srctable_keys = []
+	for key in srctable:
+		srctable_keys.append(key)
 	srctable_keys.sort()
 
-	print >>f, ""
-	print >>f, "##### translated strings #####"
-	print >>f, ""
+	content = "\n##### translated strings #####\n\n"
 	for k in srctable_keys:
 		if k in loctable and len(loctable[k]):
-			print >>f, k
-			print >>f, "==", loctable[k]
-			print >>f, ""
+			content += "%s\n==%s\n\n" % (k, loctable[k])
 			num_items += 1
 
 
-	print >>f, "##### needs translation ####"
-	print >>f,  ""
+	content += "##### needs translation #####\n\n"
 	for k in srctable_keys:
 		if not k in loctable or len(loctable[k]) == 0:
-			print >>f, k
-			print >>f, "==", srctable[k]
-			print >>f, ""
+			content += "%s\n== %s\n\n" % (k, k)
 			num_items += 1
 			new_items += 1
 
-	print >>f, "##### old translations ####"
-	print >>f, ""
+	content += "##### old translations #####\n\n"
 	for k in loctable:
 		if not k in srctable:
-			print >>f, k
-			print >>f, "==", loctable[k]
-			print >>f, ""
+			#content += "%s\n==%s\n\n" % (k, loctable[k])
 			num_items += 1
 			old_items += 1
-
-	print "%-40s %8d %8d %8d" % (outputfilename, num_items, new_items, old_items)
-	f.close()
 	
-	os.rename(tmpfilename, outputfilename)
+	f.write(content.encode("utf-8"))
+	f.close()
+	print("%-40s %8d %8d %8d" % (outputfilename, num_items, new_items, old_items))
 
 srctable = parse_source()
 
-print "%-40s %8s %8s %8s" % ("filename", "total", "new", "old")
+print("%-40s %8s %8s %8s" % ("filename", "total", "new", "old"))
 
-for filename in os.listdir("data/languages"):
+for filename in os.listdir("../data/languages"):
 	if not ".txt" in filename:
 		continue
+	if filename == "index.txt":
+		continue
 		
-	filename = "data/languages/" + filename
+	filename = "../data/languages/" + filename
 	generate_languagefile(filename, srctable, load_languagefile(filename))
-
-
-
+_input("Press enter to exit\n")