吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1300|回复: 0
收起左侧

[Python 原创] 僵毁模组标题和简介翻译

[复制链接]
梦汐 发表于 2023-4-13 01:30
[Python] 纯文本查看 复制代码
import chardet
import os
import re
from shutil import copyfile
import json
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
import time
# 环境
""" 
tencentcloud-sdk-python==3.0.871
tencentcloud-sdk-python-tmt==3.0.871
chardet==5.1.0
"""
print("请输入腾讯翻译秘钥,没有的可以去免费申请(百度有教程)")
token = credential.Credential(input("secret_id:"), input("secret_key:")
                              )

def transl(array):
    # 实例化一个http选项,可选的,没有特殊需求可以跳过
    httpProfile = HttpProfile()
    httpProfile.endpoint = "tmt.tencentcloudapi.com"
    # 实例化一个client选项,可选的,没有特殊需求可以跳过
    clientProfile = ClientProfile()
    clientProfile.httpProfile = httpProfile
    # 实例化要请求产品的client对象,clientProfile是可选的
    client = tmt_client.TmtClient(token, "ap-guangzhou", clientProfile)
    # 实例化一个请求对象,每个接口都会对应一个request对象
    req = models.TextTranslateBatchRequest()
    params = {
        "Source": "auto",
        "Target": "zh",
        "ProjectId": 0,
        "SourceTextList": array
    }
    req.from_json_string(json.dumps(params))
    resp = client.TextTranslateBatch(req)
    # 输出json格式的字符串回包
    return resp.TargetTextList

def find_info_extract(path):
    for root, dirs, files in os.walk(path):
        for file in files:
            if file == 'mod.info':
                file_name = os.path.join(root, file)
                if os.path.exists(file_name+".backup") == False:
                    copyfile(file_name, file_name+".backup")
                # ----备份源文件
                else:  # 恢复源文件
                    copyfile(file_name+".backup", file_name)
                    # break
                with open(file_name, 'rb') as f:
                    data = f.read()
                    encoding = chardet.detect(data)['encoding']
                    ascii_data = data.decode(
                        encoding)  # 写出 ascii_data.encode('utf-8', 'ignore')
                matches = re.findall(r'(.*\S)\s*=\s*(.*)$', ascii_data, re.M)
                enter = []
                index = 0
                for match in matches:
                    if match[0] == "name" or match[0] == "description":
                        enter.append(index)
                    index = index+1
                tl = transl([list(matches)[_][1] for _ in enter])
                index = 0
                for _ in enter:
                    content = list(matches[_])
                    content[1] = (tl[index]+" | "+content[1]
                                  ).replace('\r', '')+"\r"
                    matches[_] = tuple(content)
                    index += 1
                    ...
                export = None
                for match in matches:
                    if match[0] == "name" or match[0] == "description":
                        enter.append(index)
                    if export == None:
                        export = match[0]+"="+match[1]
                    else:
                        export = export+"\n"+match[0]+"="+match[1]
                    index = index+1
                print(root, '\n', tl, '\n')
                with open(file_name, 'wb') as f:
                    f.write(export.encode('utf-8', 'ignore'))
                time.sleep(0.3)

print("示例(...Steam/steamapps/workshop/content/108600)")
find_info_extract(input("模组路径:"))

免费评分

参与人数 3吾爱币 +9 热心值 +2 收起 理由
侃遍天下无二人 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
戏中人 + 1 + 1 谢谢@Thanks!
qiangqiangguai + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-25 00:41

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表