mirror of
https://github.com/ddnet/ddnet.git
synced 2024-09-20 01:24:18 +00:00
Fixed encoding error
This commit is contained in:
parent
b94c70d351
commit
5483eb6629
|
@ -8,8 +8,8 @@ source_exts = [".c", ".cpp", ".h"]
|
||||||
def parse_source():
|
def parse_source():
|
||||||
stringtable = {}
|
stringtable = {}
|
||||||
def process_line(line):
|
def process_line(line):
|
||||||
if 'Localize("' in line:
|
if b'Localize("' in line:
|
||||||
fields = line.split('Localize("', 1)[1].split('"', 1)
|
fields = line.split(b'Localize("', 1)[1].split(b'"', 1)
|
||||||
stringtable[fields[0]] = ""
|
stringtable[fields[0]] = ""
|
||||||
process_line(fields[1])
|
process_line(fields[1])
|
||||||
|
|
||||||
|
@ -23,21 +23,21 @@ def parse_source():
|
||||||
if filename[-2:] in source_exts or filename[-4:] in source_exts:
|
if filename[-2:] in source_exts or filename[-4:] in source_exts:
|
||||||
for line in open(filename, "rb"):
|
for line in open(filename, "rb"):
|
||||||
process_line(line)
|
process_line(line)
|
||||||
|
|
||||||
return stringtable
|
return stringtable
|
||||||
|
|
||||||
def load_languagefile(filename):
|
def load_languagefile(filename):
|
||||||
f = open(filename, "rb")
|
f = open(filename, "rb")
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
stringtable = {}
|
stringtable = {}
|
||||||
|
|
||||||
for i in range(0, len(lines)-1):
|
for i in range(0, len(lines)-1):
|
||||||
l = lines[i].decode("utf-8").strip()
|
l = lines[i].strip()
|
||||||
if len(l) and not l[0] == '=' and not l[0] == '#':
|
if len(l) and not l[0:1] == b"=" and not l[0:1] == b"#":
|
||||||
stringtable[l] = lines[i+1][3:].decode("utf-8").rstrip()
|
stringtable[l] = lines[i+1][3:].rstrip()
|
||||||
|
|
||||||
return stringtable
|
return stringtable
|
||||||
|
|
||||||
def generate_languagefile(outputfilename, srctable, loctable):
|
def generate_languagefile(outputfilename, srctable, loctable):
|
||||||
|
@ -52,28 +52,27 @@ def generate_languagefile(outputfilename, srctable, loctable):
|
||||||
srctable_keys.append(key)
|
srctable_keys.append(key)
|
||||||
srctable_keys.sort()
|
srctable_keys.sort()
|
||||||
|
|
||||||
content = "\n##### translated strings #####\n\n"
|
content = b"\n##### translated strings #####\n\n"
|
||||||
for k in srctable_keys:
|
for k in srctable_keys:
|
||||||
if k in loctable and len(loctable[k]):
|
if k in loctable and len(loctable[k]):
|
||||||
content += "%s\n== %s\n\n" % (k, loctable[k])
|
content += k + b"\n== " + loctable[k] + b"\n\n"
|
||||||
num_items += 1
|
num_items += 1
|
||||||
|
|
||||||
|
content += b"##### needs translation #####\n\n"
|
||||||
content += "##### needs translation #####\n\n"
|
|
||||||
for k in srctable_keys:
|
for k in srctable_keys:
|
||||||
if not k in loctable or len(loctable[k]) == 0:
|
if not k in loctable or len(loctable[k]) == 0:
|
||||||
content += "%s\n== \n\n" % (k)
|
content += k + b"\n== \n\n"
|
||||||
num_items += 1
|
num_items += 1
|
||||||
new_items += 1
|
new_items += 1
|
||||||
|
|
||||||
content += "##### old translations #####\n\n"
|
content += b"##### old translations #####\n\n"
|
||||||
for k in loctable:
|
for k in loctable:
|
||||||
if not k in srctable:
|
if not k in srctable:
|
||||||
content += "%s\n== %s\n\n" % (k, loctable[k])
|
content += k + b"\n== " + loctable[k] + b"\n\n"
|
||||||
num_items += 1
|
num_items += 1
|
||||||
old_items += 1
|
old_items += 1
|
||||||
|
|
||||||
f.write(content.encode("utf-8"))
|
f.write(content)
|
||||||
f.close()
|
f.close()
|
||||||
print("%-40s %8d %8d %8d" % (outputfilename, num_items, new_items, old_items))
|
print("%-40s %8d %8d %8d" % (outputfilename, num_items, new_items, old_items))
|
||||||
|
|
||||||
|
@ -86,6 +85,6 @@ for filename in os.listdir("../data/languages"):
|
||||||
continue
|
continue
|
||||||
if filename == "index.txt":
|
if filename == "index.txt":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
filename = "../data/languages/" + filename
|
filename = "../data/languages/" + filename
|
||||||
generate_languagefile(filename, srctable, load_languagefile(filename))
|
generate_languagefile(filename, srctable, load_languagefile(filename))
|
||||||
|
|
Loading…
Reference in a new issue