欢迎光临散文网 会员登陆 & 注册

辐射4 自动翻译MOD

2023-07-22 07:07 作者:白纸猫又w  | 我要投稿
  1. 打开xTranslator,Ctrl+Alt+A勾选全部,右键标记为已翻译,导出为XML文件。

  2. 修改python里的路径,按下运行脚本按钮,等待运行结束。

  3. xTranslator选择导入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')


辐射4 自动翻译MOD的评论 (共 条)

分享到微博请遵守国家法律