2024-07-27 14:02:19 +08:00
|
|
|
import sys, time
|
|
|
|
|
2024-08-17 11:01:48 +08:00
|
|
|
sys.path.insert(0, "./LunaTranslator")
|
2024-03-06 17:19:15 +08:00
|
|
|
from translator.baidu_ai import TS
|
2024-07-27 14:02:19 +08:00
|
|
|
|
|
|
|
|
2024-01-08 23:37:00 +08:00
|
|
|
class TS1(TS):
|
2024-07-27 14:02:19 +08:00
|
|
|
|
|
|
|
@property
|
|
|
|
def srclang(self):
|
|
|
|
return "zh"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def tgtlang(self):
|
|
|
|
return self.xxxxx
|
|
|
|
|
|
|
|
@tgtlang.setter
|
|
|
|
def tgtlang(self, _):
|
|
|
|
self.xxxxx = _
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
import os, json
|
|
|
|
|
|
|
|
f = "zh.json"
|
|
|
|
with open("./files/lang/" + f, "r", encoding="utf8") as ff:
|
|
|
|
js = ff.read()
|
|
|
|
js = json.loads(js)
|
|
|
|
xxx = {
|
|
|
|
"en": "en",
|
|
|
|
"cht": "cht",
|
|
|
|
}
|
|
|
|
needpop = []
|
2024-01-08 23:37:00 +08:00
|
|
|
for k in js:
|
2024-07-27 14:02:19 +08:00
|
|
|
kk = False
|
|
|
|
try:
|
|
|
|
k.encode("ascii")
|
|
|
|
print(k)
|
|
|
|
kk = True
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
if k not in js or kk:
|
|
|
|
needpop.append(k)
|
2024-01-08 23:37:00 +08:00
|
|
|
for k in needpop:
|
2024-07-27 14:02:19 +08:00
|
|
|
js.pop(k)
|
|
|
|
with open(f"./files/lang/" + f, "w", encoding="utf8") as ff:
|
|
|
|
ff.write(json.dumps(js, ensure_ascii=False, sort_keys=False, indent=4))
|
|
|
|
a = TS1("baiduapi")
|
2025-01-14 15:06:59 +08:00
|
|
|
for kk in os.listdir("./files/lang"):
|
|
|
|
with open(f"./files/lang/{kk}", "r", encoding="utf8") as ff:
|
2024-07-27 14:02:19 +08:00
|
|
|
|
|
|
|
jsen = json.loads(ff.read())
|
|
|
|
|
|
|
|
needpop = []
|
|
|
|
for k in jsen:
|
|
|
|
if k not in js:
|
|
|
|
needpop.append(k)
|
|
|
|
print(kk, needpop)
|
2024-01-08 23:37:00 +08:00
|
|
|
for k in needpop:
|
2024-07-27 14:02:19 +08:00
|
|
|
jsen.pop(k)
|
2025-01-14 15:06:59 +08:00
|
|
|
with open(f"./files/lang/{kk}", "w", encoding="utf8") as ff:
|
2024-07-27 14:02:19 +08:00
|
|
|
ff.write(json.dumps(jsen, ensure_ascii=False, sort_keys=False, indent=4))
|
2025-01-14 15:06:59 +08:00
|
|
|
|
2024-01-08 23:37:00 +08:00
|
|
|
for k in js:
|
2024-07-27 14:02:19 +08:00
|
|
|
|
|
|
|
if k not in jsen or jsen[k] == "":
|
2025-01-14 15:06:59 +08:00
|
|
|
a.tgtlang = xxx.get(kk.split(".")[0])
|
|
|
|
if not a.tgtlang:
|
|
|
|
jsen[k] = ""
|
|
|
|
else:
|
|
|
|
jsen[k] = list(a.translate(k))[0]
|
|
|
|
print(k, jsen[k])
|
|
|
|
with open(f"./files/lang/{kk}", "w", encoding="utf8") as ff:
|
2024-07-27 14:02:19 +08:00
|
|
|
ff.write(
|
|
|
|
json.dumps(jsen, ensure_ascii=False, sort_keys=False, indent=4)
|
|
|
|
)
|