2 match
= re
.search('(.*)/', sys
.argv
[0])
4 os
.chdir(match
.group(1))
7 source_exts
= [".c", ".cpp", ".h"]
11 def process_line(line
):
12 if 'Localize("'.encode() in line
:
13 fields
= line
.split('Localize("'.encode(), 1)[1].split('"'.encode(), 1)
14 stringtable
[fields
[0]] = ""
15 process_line(fields
[1])
17 for root
, dirs
, files
in os
.walk("src"):
19 filename
= os
.path
.join(root
, name
)
21 if os
.sep
+ "external" + os
.sep
in filename
:
24 if filename
[-2:] in source_exts
or filename
[-4:] in source_exts
:
25 for line
in open(filename
, "rb"):
30 def load_languagefile(filename
):
31 f
= open(filename
, "rb")
37 for i
in range(0, len(lines
)-1):
39 if len(l
) and not l
[0:1] == "=".encode() and not l
[0:1] == "#".encode():
40 stringtable
[l
] = lines
[i
+1][3:].rstrip()
44 def generate_languagefile(outputfilename
, srctable
, loctable
):
45 f
= open(outputfilename
, "wb")
53 srctable_keys
.append(key
)
56 content
= "\n##### translated strings #####\n\n".encode()
57 for k
in srctable_keys
:
58 if k
in loctable
and len(loctable
[k
]):
59 content
+= k
+ "\n== ".encode() + loctable
[k
] + "\n\n".encode()
62 content
+= "##### needs translation #####\n\n".encode()
63 for k
in srctable_keys
:
64 if not k
in loctable
or len(loctable
[k
]) == 0:
65 content
+= k
+ "\n== \n\n".encode()
69 content
+= "##### old translations #####\n\n".encode()
72 content
+= k
+ "\n== ".encode() + loctable
[k
] + "\n\n".encode()
78 print("%-40s %8d %8d %8d" % (outputfilename
, num_items
, new_items
, old_items
))
80 srctable
= parse_source()
82 print("%-40s %8s %8s %8s" % ("filename", "total", "new", "old"))
84 for filename
in os
.listdir("data/languages"):
85 if not ".txt" in filename
:
87 if filename
== "index.txt":
90 filename
= "data/languages/" + filename
91 generate_languagefile(filename
, srctable
, load_languagefile(filename
))