forked from renpy/renpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_strings.py
executable file
·79 lines (52 loc) · 1.58 KB
/
build_strings.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
#!/usr/bin/env python
import collections
import glob
import re
import os
# A map from string to filename, line number where the string is found.
strings = collections.defaultdict(list)
def process(fn):
lineno = 0
for data in file(fn, "r"):
lineno += 1
matches = [ ]
matches += re.finditer(r'\bu\"(\\"|[^"])+\"', data)
matches += re.finditer(r"\bu\'(\\'|[^'])+\'", data)
for m in matches:
s = m.group(0)[2:-1]
if "\\u" in s:
continue
if len(s) == 1:
continue
strings[s].append("%s:%d" % (fn, lineno))
if __name__ == "__main__":
files = [ ]
files += glob.glob("launcher/*.rpy")
files += glob.glob("common/*.rpy")
files += glob.glob("common/*.rpym")
files += glob.glob("common/_layout/*.rpym")
files += glob.glob("common/_compat/*.rpym")
if "launcher/strings.rpy" in files:
files.remove("launcher/strings.rpy")
for fn in files:
process(fn)
converse = [ ]
for k, v in strings.iteritems():
v = " ".join(sorted(v))
converse.append((v, k))
converse.sort()
f = file("launcher/strings.rpy", "w")
files = set(i for i in os.listdir("launcher") if i.endswith(".rpy"))
print >>f, """\
init python:
LAUNCHER_RPYS = %r
TRANSLATION_STRINGS = [
""" % files
for v, k in converse:
# print
# print "#:", v
# print "#, python-format"
print >>f, " u\"%s\"," % unicode(k)
print >>f, """\
]
"""