-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathcreatepla.py
55 lines (47 loc) · 1.49 KB
/
createpla.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
#!/usr/bin/env python3
import os, sys
import deepl
x = open("mybotr.po", "a")
with open('mybot.po', encoding='UTF-8') as f:
idblock=""
idblock2=""
lines = f.readlines()
for row in lines:
if row[0] == '"':
idblock = idblock + row
xr2 = deepl.translate(source_language="RU", target_language="EN", text=row)
idblock2 = idblock2 + xr2
print(idblock)
print(idblock2)
print("1")
if 'msgid ' in row:
print("2")
print("2-1")
if 'msgid ""' in row:
idblock= idblock + 'msgid ""' + "\n"
idblock2= idblock2 + 'msgstr ""' + "\n"
#x.write('msgid ""\n')
else:
idblock= idblock + row + "\n"
xb2 = deepl.translate(source_language="RU", target_language="EN", text=row[7:])
idblock2= idblock2 + 'msgstr ' + xb2
continue
print(row[7:])
#x.write('msgstr ' + row[6:])
elif 'msgstr' in row:
print("3")
x.write(idblock)
x.write(idblock2)
idblock = ""
idblock2 = ""
continue
elif row[0] == "\n":
print("4")
x.write('\n')
#idblock= idblock + row
#idblock2= idblock2 + row
else:
xrow = deepl.translate(source_language="RU", target_language="EN", text=row)
x.write(xrow)
x.close()
f.close()