輻射4 自動翻譯MOD
打開xTranslator,Ctrl+Alt+A勾選全部,右鍵標記為已翻譯,導(dǎo)出為XML文件。
修改python里的路徑,按下運行腳本按鈕,等待運行結(jié)束。
xTranslator選擇導(dǎo)入xml,保存為翻譯文件。

import xml.etree.ElementTree as ET
import json
from shutil import copyfile
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
token = credential.Credential(
? ? "這里輸入你的騰訊翻譯tk")
def transl(array):
? ? httpProfile = HttpProfile()
? ? httpProfile.endpoint = "tmt.tencentcloudapi.com"
? ? clientProfile = ClientProfile()
? ? clientProfile.httpProfile = httpProfile
? ? client = tmt_client.TmtClient(token, "ap-guangzhou", clientProfile)
? ? req = models.TextTranslateBatchRequest()
? ? params = {
? ? ? ? "Source": "auto",
? ? ? ? "Target": "zh",
? ? ? ? "ProjectId": 0,
? ? ? ? "SourceTextList": array
? ? }
? ? req.from_json_string(json.dumps(params))
? ? resp = client.TextTranslateBatch(req)
? ? return resp.TargetTextList
tree = ET.parse(r"你的xml路徑")
root = tree.getroot()
value_node = root.findall('./Content/')
for string_node in value_node:
? ? value = string_node.find('Dest').text
? ? if not "\n" in value:
? ? ? ? try:
? ? ? ? ? ? tl = transl([value])[0]
? ? ? ? except:
? ? ? ? ? ? tl = '[翻譯出錯]'+value
? ? ? ? string_node.find('Dest').text =tl
? ? ? ? print(value, tl)
tree.write(r"你的xml路徑", encoding='utf-8')
