generated from DRincs-Productions/renpy-translations-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
translation_convertor_potorpy.py
153 lines (136 loc) · 6.59 KB
/
translation_convertor_potorpy.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import os
import re
import shutil
from fileinput import FileInput
from glob import glob
# ATTENTION: there must not be 2 equal key or value
# regex: https://www.w3schools.com/python/python_regex.asp
dict = {
# search_text : replace_text
# start
r'msgid ""\nmsgstr ""\n(.*)\n(.*)\n(.*)\n(.*)': r'',
r'\n"Plural-Forms(.*)': r'',
r'\n"X-Crowdin(.*)': r'',
r'\n"Project-Id-V(.*)': r'',
r'\n"Content-Type(.*)': r'',
r'\n"Language-Tea(.*)': r'',
r'\n"Language:(.*)': r'',
r'\n"PO-Revision-(.*)': r'',
r'\n"Большой(.*)': r'',
r'\\n"\n"': r'\\n',
r'\\'+'"': r'§§§§§§§§',
# Effect
r' \[nointeract\]"': r'" nointeract',
r' \[withfade\]"': r'" with fade',
r' \[withdissolve\]"': r'" with dissolve',
r' \[withslowdissolve\]"': r'" with slowdissolve',
r' \[withhpunch\]"': r'" with hpunch',
r' \[withflash\]"': r'" with flash',
r' \[withvpunch\]"': r'" with vpunch',
r' \[withDissolve20\]"': r'" with Dissolve(2.0)',
r' \[withDissolve1\]"': r'" with Dissolve(1)',
r' \[withDissolvey3\]"': r'" with Dissolve(.3)',
r' \[multiple2\]"': r'" (multiple=2)',
r'msgid "\[nvl_clear\]"': r' # nvl clear',
r'msgstr "\[nvl_clear\]"': r' nvl clear',
# first
r'msgid "(.*?) \[special_delimiter\] (.*?)"': r' # "\1" "\2"',
r'msgstr "(.*?) \[special_delimiter\] (.*?)"': r' "\1" "\2"',
r':\nmsgid "(.*?)"': r':\n # "\1"',
r' #(.*?)\nmsgstr "\[_(.*?)\_] (.*?)"': r' #\1\n \2 "\3"',
r' #(.*?)\nmsgstr "\[_(.*?)\_](.*?)"': r' #\1\n \2 "\3"',
r' # (.*?)\nmsgstr "(.*?)"': r' # \1\n "\2"',
# after
r' # "\[_(.*?)\_] (.*?)"': r' # \1 "\2"',
# Comment
r':\n # ': r':\n\n # ',
r'rpy:(.*?) #-#-# translate': r'rpy:\1\ntranslate',
r'strings: #\|#\|# # ': r'strings:\n\n# ',
r'updated at (.*?)-(.*?)-(.*?) (.*?):(.*?) #\|#\|# # ': r'updated at \1-\2-\3 \4:\5\n\n# ',
# end
r'msgid "(.*?)"': r' old "\1"',
r'msgstr "(.*?)"': r' new "\1"',
r'\n#(.*?)\n old "': r'\n #\1\n old "',
r'\n\n# TODO: Translation updated': r'# TODO: Translation updated',
r'§§§§§§§§': r'\\'+'"',
r'# TODO: Translation updated at (.*?)-(.*?)-(.*?) (.*?):(.*?) #\|#\|# # §translate ': r'# TODO: Translation updated at \1-\2-\3 \4:\5\n\ntranslate ',
r'\n# §translate': r'\ntranslate',
r'\n#§translate': r'\ntranslate',
}
# Creating a function to replace the text
def replacetext(search_text, replace_text, pathFile, languege):
# Read in the file
with open(pathFile, "r+", encoding="utf8") as file:
filedata = file.read()
# c = re.compile(search_text)
# Replace the target string
# filedata = filedata.replace(search_text, replace_text)
filedata = re.sub(search_text, replace_text, filedata)
# TODO: to improve
filedata = re.sub(r'"\n (.*?)_s_(.*?) "',
r'"\n \1 \2 "', filedata)
filedata = re.sub(r'"\n (.*?)_s_(.*?) "',
r'"\n \1 \2 "', filedata)
filedata = re.sub(r'"\n (.*?)_s_(.*?) "',
r'"\n \1 \2 "', filedata)
filedata = re.sub(r'"\n (.*?)_s_(.*?) "',
r'"\n \1 \2 "', filedata)
filedata = re.sub(r'"\n (.*?)_s_(.*?) "',
r'"\n \1 \2 "', filedata)
filedata = re.sub(r'"\n (.*?)_s_(.*?) "',
r'"\n \1 \2 "', filedata)
filedata = re.sub(r'"\n (.*?)_s_(.*?) "',
r'"\n \1 \2 "', filedata)
filedata = re.sub(r'"\n (.*?)_s_(.*?) "',
r'"\n \1 \2 "', filedata)
filedata = re.sub(r'"(.*?)\n (.*?)_s_(.*?) "',
r'"\1\n \2 \3 "', filedata)
filedata = re.sub(r'"(.*?)\n (.*?)_s_(.*?) "',
r'"\1\n \2 \3 "', filedata)
filedata = re.sub(r'"(.*?)\n (.*?)_s_(.*?) "',
r'"\1\n \2 \3 "', filedata)
filedata = re.sub(r'"(.*?)\n (.*?)_s_(.*?) "',
r'"\1\n \2 \3 "', filedata)
filedata = re.sub(r':\n\n # (.*?)_s_(.*?) "',
r':\n\n # \1 \2 "', filedata)
filedata = re.sub(r':\n\n # (.*?)_s_(.*?) "',
r':\n\n # \1 \2 "', filedata)
filedata = re.sub(r':\n\n # (.*?)_s_(.*?) "',
r':\n\n # \1 \2 "', filedata)
filedata = re.sub(r':\n\n # (.*?)_s_(.*?) "',
r':\n\n # \1 \2 "', filedata)
filedata = re.sub(r':\n\n # (.*?)_s_(.*?) "',
r':\n\n # \1 \2 "', filedata)
filedata = re.sub(r':\n\n # (.*?)_s_(.*?) "',
r':\n\n # \1 \2 "', filedata)
filedata = re.sub(r':\n\n # (.*?)_s_(.*?) "',
r':\n\n # \1 \2 "', filedata)
filedata = re.sub(r':\n\n # (.*?)_s_(.*?) "',
r':\n\n # \1 \2 "', filedata)
filedata = re.sub(r'crowdin', languege, filedata)
# Write the file out again
with open(pathFile, 'w', encoding="utf8") as file:
file.write(filedata)
return True
def replaceDictionary(pathFile, dict={}, languege="crowdin"):
newpathFile = fileRename(pathFile, extension=".rpy")
print(pathFile)
for search_text in dict.keys():
replacetext(pathFile=newpathFile, search_text=search_text,
replace_text=dict[search_text], languege=languege)
def getListFiles(extension, languege="**"):
# Get the list of all files and directories
path = "game/tl/"
dir_list = glob(path + languege+"/*"+extension, recursive=True)
if languege != "**":
dir_list = dir_list + \
glob(path + languege+"/**/*"+extension, recursive=True)
return dir_list
def potorpy(languege):
for path in getListFiles(extension=".po", languege=languege):
replaceDictionary(path, dict=dict, languege=languege)
def fileRename(pathFile, extension):
pre, ext = os.path.splitext(pathFile)
shutil.copyfile(pathFile, pre + extension)
return pre + extension
potorpy("crowdin")