-
Notifications
You must be signed in to change notification settings - Fork 0
/
localize.py
executable file
·105 lines (90 loc) · 3 KB
/
localize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/python3
# coding: UTF-8
import sys
from os import makedirs
import os
from argparse import ArgumentParser
def process(filename, out_folder):
print("Reading file \"" + filename + "\"")
f = open(filename, 'r')
tags = []
values = []
basename = os.path.basename(os.path.splitext(filename)[0])
for line in f:
list = line.replace("\n", "").split("=")
if (len(list) == 2):
tags.append(list[0])
values.append(list[1])
string = "#pragma once\nconst char* " + basename + "_tags[]={\"locale\""
for tag in tags:
string += ",\"" + tag + "\""
string += "};\n"
string += "const char* " + basename + "_values[]={\"" + basename + "\""
for value in values:
string += ",\"" + value + "\""
string += "};\n"
string += "int " + basename + "_num = " + str(len(tags)) + ";"
out_file = os.path.join(out_folder, basename + ".h")
wfile = open(out_file, "wb")
# For creating the languages.h file
ostring = string
string = ""
for char in ostring:
# German ß should be replaced with ss
if (char == u"ß"):
string += "ss"
# Esperanto ^ letters can be replaced with x
# ĝ -> gx ĉ -> cx etc
elif (char == u"ĝ"):
string += u"â"
elif (char == u"ŝ"):
string += u"á"
elif (char == u"ĉ"):
string += u"à"
elif (char == u"ĵ"):
string += u"ã"
elif (char == u"ŭ"):
string += u"å"
else:
string += char
wfile.write(string.encode("ISO-8859-15"))
wfile.close()
return basename
root = os.path.dirname(os.path.realpath(__file__))
print('ARGS:', sys.argv, file=sys.stderr)
parser = ArgumentParser()
parser.add_argument('filenames', nargs='*')
parser.add_argument('-o', '--out-folder', default='')
args = parser.parse_args()
fileNames = [process(filename, args.out_folder) for filename in args.filenames]
makedirs(root + "/source/localizations/generated/", exist_ok=True)
languagesFile = open(root + "/source/localizations/generated/languages.h", "w")
languagesFile.write("#ifdef LOCALE_CPP\n#pragma once\n")
for name in fileNames:
languagesFile.write("#include \"" + name + ".h\"\n")
languagesFile.write("const int numLanguages = " + str(len(fileNames)) + ";\n")
languagesFile.write("const char** languagesTags[] = {")
comma = False
for name in fileNames:
if (comma):
languagesFile.write(",")
languagesFile.write(name + "_tags")
comma = True
languagesFile.write("};\n")
languagesFile.write("const char** languagesValues[] = {")
comma = False
for name in fileNames:
if (comma):
languagesFile.write(",")
languagesFile.write(name + "_values")
comma = True
languagesFile.write("};\n")
languagesFile.write("const int languagesNums[] = {")
comma = False
for name in fileNames:
if (comma):
languagesFile.write(",")
languagesFile.write(name + "_num")
comma = True
languagesFile.write("};\n#endif\n")
languagesFile.close()