Skip to content

Commit 09b30cc

Browse files
committed
feat: add extractor
1 parent 64c1832 commit 09b30cc

File tree

8 files changed

+3797
-4
lines changed

8 files changed

+3797
-4
lines changed

ReadMe.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,56 @@ python ddcs.py
2525
```
2626
注意:请务必使用管理员权限启动终端。
2727

28+
## 自动提取 (Beta)
29+
30+
通过正则和简单的代码分析, 自动提取出 Docker Desktop 页面中出现的文本,
31+
并保存到 [extract_config.py](./lib/extract_config.py).
32+
33+
### 对于使用者
34+
35+
目前自动提取翻译属于 Beta 状态, 因此需要在使用 ddcs.py 时显式地声明使用 v2, 即
36+
37+
```bash
38+
python ddcs.py --v2
39+
```
40+
41+
### 对于翻译者 & 开发者
42+
43+
1. 运行自动提取 (仅在 Docker Desktop 发布新版本后需要)
44+
45+
```shell
46+
# 默认情况下与 ddcs.py 一致, 自动寻找本机 Docker Desktop app.asar 并解包
47+
python ddcs_extract.py
48+
```
49+
50+
```shell
51+
# path 参数为手动解包 asar 之后的路径
52+
python ddcs_extract.py --path xxx
53+
```
54+
2. 进行翻译
55+
56+
在 [extract_config.py](./lib/extract_config.py) 中的 config 是一个元组列表, 即 `[(英文, 中文), ...]`. 运行自动提取后,
57+
新增的元组项包含一个英文文本, 和一个为空字符串(`""`)的中文文本, 请在 [extract_config.py](./lib/extract_config.py)
58+
搜索空字符串并进行翻译.
59+
60+
**注意事项**:
61+
- 英文文本可能为包含 js 变量的模板字符串, 如 `Images (${c.images.count})`, 翻译后的中文应当保留变量, 即
62+
`镜像(${c.images.count}`
63+
- 英文文本可能为包含替换字段(`{0},{1},etc.`)的格式化字符串,如 `Select {0} in the {1} column to see it running.`,
64+
翻译后的中文应当保留替换字段, 即`在 {1} 列选择 {0} 以查看其运行情况`. 如果替换字段遗漏, 在替换阶段也会有警告日志输出.
65+
- 对于不需要翻译的项目, **请不要删除**, 而是将中文值设为 `None`, 如 `("Python", None)`
66+
- 对于没有自动提取的文本, 请添加到 [extract_config_manually.py](./lib/extract_config_manually.py) 中
67+
68+
3. 验证翻译
69+
70+
```bash
71+
python ddcs.py --v2
72+
```
73+
替换后启动 Docker Desktop, 验证各个页面. 因为自动提取显然不可能足够精准, 因此可能会:
74+
- 遗漏部分内容. 表现: 某些地方仍为英文; 解决方法: 添加到 extract_config_manually.py 或者优化 extract.py
75+
- 错误提取. 表现: Docker Desktop 页面出现报错; 解决方法: 根据报错定位错误文本并修复 (大多出现在
76+
extract_config_manually 中, 如漏掉引号等)
77+
2878
## 更多问题?
2979
有问题的可以扫码加群咨询。
3080
![](images/1.jpg)

ddcs.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
#
55
# @Time : 2024/8/9 下午4:17
66
# @Author : ASXE
7-
7+
import argparse
88
import time
9+
from pathlib import Path
910

1011
from common import log
12+
from lib.extract import replace
1113
from lib.processor import DDProcessor, FileProcessor
1214

1315

@@ -43,7 +45,25 @@ def run(root_path, config_path):
4345
DDProcessor(False)
4446

4547

48+
@cost_time
49+
def run_v2(root_path: str):
50+
log.info("脚本已启动...")
51+
time.sleep(1)
52+
53+
DDProcessor(True)
54+
log.info("汉化开始")
55+
replace(Path(root_path))
56+
DDProcessor(False)
57+
58+
4659
if __name__ == "__main__":
47-
root_path = './app/build/'
48-
config_path = './config.json'
49-
run(root_path, config_path)
60+
parser = argparse.ArgumentParser()
61+
parser.add_argument("--v2", action="store_true")
62+
args = parser.parse_args()
63+
64+
root_path = "./app/build/"
65+
config_path = "./config.json"
66+
if args.v2:
67+
run_v2(root_path)
68+
else:
69+
run(root_path, config_path)

ddcs_extract.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import argparse
2+
from pathlib import Path
3+
4+
from lib.extract import generate_config
5+
from lib.processor import DDProcessor
6+
7+
if __name__ == "__main__":
8+
parser = argparse.ArgumentParser()
9+
parser.add_argument("--path", type=str, default=None)
10+
args = parser.parse_args()
11+
12+
if args.path is None:
13+
DDProcessor(True)
14+
path = Path("./app/build")
15+
else:
16+
path = Path(args.path)
17+
generate_config(path)

0 commit comments

Comments
 (0)