Toc
  1. resources.pak解包
  2. 写脚本翻译
  3. 效果
Toc
0 results found
Rayi
Chrome Devtools 汉化教程
2021/05/07 瞎折腾 chrome 汉化

chrome的开发者工具和控制台汉化

resources.pak解包

文件默认目录为:C:\Program Files\Google\Chrome\Application\90.0.4430.93

备份后再解包

解包网上工具很多

https://www.52pojie.cn/thread-705822-1-1.html

解出来这些

image-20210507211003460

语言包在unknown中,把unknown文件夹拖进vscode进行搜索,搜索关键词可以是控制台中任意的英文关键词,即可找到相关文件

image-20210507211112173

写脚本翻译

import re
import requests
import json
import time
import random
from hashlib import md5

def make_md5(s, encoding='utf-8'):
    return md5(s.encode(encoding)).hexdigest()

def translateBaidu(text):
    # Set your own appid/appkey.
	appid = 'your_appid'
	appkey = 'your_appk'
	from_lang = 'en'
	to_lang =  'zh'
	endpoint = 'http://api.fanyi.baidu.com'
	path = '/api/trans/vip/translate'
	url = endpoint + path
	query = text
	salt = random.randint(32768, 65536)
	sign = make_md5(appid + query + str(salt) + appkey)
	headers = {'Content-Type': 'application/x-www-form-urlencoded'}
	payload = {'appid': appid, 'q': query, 'from': from_lang, 'to': to_lang, 'salt': salt, 'sign': sign}
	r = requests.post(url, params=payload, headers=headers)
	result = r.json()
	return result['trans_result'][0]['dst']

with open('27462','r',encoding='utf8') as f:
	resources = f.readlines()

new_resources = []
with open("new_27462",'a',encoding='utf8') as f:
	for i in resources:
		try:
			replace_word = re.findall(r'"message": "(.+?)"',i)[0]
			zh = translateBaidu(replace_word)
			print(zh)
			f.write(i.replace(replace_word,zh).strip() + '\n')
		except Exception as e:
			f.write(i.strip() + '\n')

翻译完后进行简单润色,把不准的替换下,即可再把翻译完的文件扔到unknown文件夹下

进行打包后替换掉Chrome安装目录的同名文件即可

效果

image-20210507211631054

image-20210507211700039

一定要备份源文件啊

本文作者:Rayi
版权声明:本文首发于Rayi的博客,转载请注明出处!