代码拉取完成,页面将自动刷新
同步操作将从 muyoo/RPGmakerMV_translator 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import json
import clipboard
import re
import time
import os
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.tmt.v20180321 import tmt_client, models
def tran(input):
try:
cred = credential.Credential("AKIDRfcIk1bn45q5e4b4QVIbdOxGI3YRu9yW", "OGq9AvQdakdFruA8qHTPkofHby4tQggO")
httpProfile = HttpProfile()
httpProfile.endpoint = "tmt.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = tmt_client.TmtClient(cred, "ap-beijing", clientProfile)
req = models.TextTranslateRequest()
params = '{"SourceText":"'+input+'","Source":"ja","Target":"zh","ProjectId":0}'
try:
req.from_json_string(params)
except json.decoder.JSONDecodeError:
print(req)
return 'ERROR'
resp = client.TextTranslate(req)
try:
return json.loads(resp.to_json_string())['TargetText']
except json.decoder.JSONDecodeError:
print(resp.to_json_string())
return 'ERROR'
except TencentCloudSDKException as err:
print(err)
path = r'C:\Users\Muyoo\Desktop\支配の魔法ver1.70\支配の魔法ver1.70\www\data'
oldtext=[]
newtext=[]
for filename in os.listdir(path):
if re.match('CommonEvents.json',filename):
oldtext=[]
newtext=[]
print("--------------------"+filename+"--------------------")
filename=os.path.join(path,filename)
print(filename)
with open(filename, 'r',encoding='utf-8') as f:
data = json.load(f)
for item in range(len(data)):
if not data[item]: continue
for item3 in range(len(data[item]['list'])):
#401 231 402 118 119
if data[item]['list'][item3]['code'] in (401,402,118,119):
for fin in range(len(data[item]['list'][item3]['parameters'])):
tmp=data[item]['list'][item3]['parameters'][fin]
if tmp!='' and not isinstance(tmp,int):
print("原文【"+tmp+"】")
tmps=re.split(r'(<|>|【|】|\[\d+\]|「|」|\\.)',tmp)
print(tmps)
for init in range(len(tmps)):
if not re.match('[<>【】「」(\[\d+\])(\\\\.)]+',tmps[init]) and tmps[init]!='':
haveindex=0
try:
haveindex=oldtext.index(tmps[init])
tmps[init]=newtext[haveindex]
except ValueError:
oldtext.append(tmps[init])
jifan=tran(tmps[init])
if(jifan=='ERROR'):
tmps[init]=input("翻译:")
else:
tmps[init]=jifan
newtext.append(tmps[init])
time.sleep(0.1)
output=''.join(tmps)
print("机翻:"+output)
#clipboard.copy(output)
#minput=input("翻译:")
#if minput=='':
data[item]['list'][item3]['parameters'][fin]=output
#else:
# data[item]['list'][item3]['parameters'][fin]=minput
#print("结果:"+data[item]['list'][item3]['parameters'][fin])
print()
with open(filename,'w',encoding='utf-8') as f:
json.dump(data,f, ensure_ascii=False)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。