qwen-mt-cli 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ *.egg
8
+ .eggs/
9
+
10
+ # Virtual environments
11
+ .venv/
12
+ venv/
13
+
14
+ # IDE
15
+ .idea/
16
+ .vscode/
17
+ *.swp
18
+ *.swo
19
+
20
+ # OS
21
+ .DS_Store
22
+ Thumbs.db
23
+
24
+ # Environment
25
+ .env
26
+
27
+ # QMT local data
28
+ .qmt/
29
+
30
+ # Test files
31
+ *.xlsx
32
+
33
+ # Qoder
34
+ .qoder/
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2025 镭屿
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,258 @@
1
+ Metadata-Version: 2.4
2
+ Name: qwen-mt-cli
3
+ Version: 0.2.0
4
+ Summary: Qwen-MT CLI - Command-line translation tool powered by Qwen-MT with vector-based term matching
5
+ Project-URL: Homepage, https://github.com/leiyu/qwen-mt-cli
6
+ Project-URL: Repository, https://github.com/leiyu/qwen-mt-cli
7
+ Project-URL: Issues, https://github.com/leiyu/qwen-mt-cli/issues
8
+ Author-email: 镭屿 <jiayu.cly@alibaba-inc.com>
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: cli,dashscope,i18n,localization,qwen,translation
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Internationalization
22
+ Classifier: Topic :: Text Processing :: Linguistic
23
+ Requires-Python: >=3.10
24
+ Requires-Dist: click>=8.1
25
+ Requires-Dist: numpy>=1.24
26
+ Requires-Dist: openai>=1.0
27
+ Requires-Dist: openpyxl>=3.1
28
+ Requires-Dist: pandas>=2.0
29
+ Requires-Dist: prompt-toolkit>=3.0
30
+ Requires-Dist: rich>=13.0
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest>=7.0; extra == 'dev'
33
+ Requires-Dist: ruff>=0.4; extra == 'dev'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # QMT - Qwen-MT CLI
37
+
38
+ 基于通义千问机器翻译模型 (Qwen-MT) 的命令行翻译工具。支持单句翻译、交互式 REPL、CSV/Excel 批量翻译,并提供术语表、翻译记忆、领域提示等专业翻译辅助功能。
39
+
40
+ ## 安装
41
+
42
+ 需要 Python >= 3.10。
43
+
44
+ ```bash
45
+ pip install -e .
46
+ ```
47
+
48
+ 安装后即可使用 `qmt` 命令。
49
+
50
+ ## 配置
51
+
52
+ 设置 DashScope API Key([申请地址](https://dashscope.console.aliyun.com/)):
53
+
54
+ ```bash
55
+ export DASHSCOPE_API_KEY="sk-xxxxxxxx"
56
+ ```
57
+
58
+ 也可以通过 `--api-key` 参数逐次传入。
59
+
60
+ ## 快速开始
61
+
62
+ ```bash
63
+ # 翻译文本
64
+ qmt "你好世界" -t English
65
+
66
+ # 指定模型
67
+ qmt "Hello World" -t Chinese -m qwen-mt-plus
68
+
69
+ # 翻译文件
70
+ qmt -f article.txt -t English
71
+
72
+ # 管道输入
73
+ echo "你好" | qmt -t English
74
+
75
+ # 流式输出
76
+ qmt "你好世界" -t English --stream
77
+
78
+ # 交互式模式
79
+ qmt -i -t English
80
+ ```
81
+
82
+ ## 可用模型
83
+
84
+ | 模型 | 特点 | 流式 | 语言数 |
85
+ |------|------|------|--------|
86
+ | `qwen-mt-plus` | 最高翻译质量,适用于专业领域 | - | 92 |
87
+ | `qwen-mt-flash` | 通用首选,效果/速度/成本平衡 (默认) | 支持 | 92 |
88
+ | `qwen-mt-lite` | 最快响应速度,适用于实时场景 | 支持 | 31 |
89
+
90
+ ## 批量翻译
91
+
92
+ 支持 CSV (.csv/.tsv) 和 Excel (.xlsx/.xls) 文件的批量翻译。翻译文件第一列内容,结果追加为新列。
93
+
94
+ ```bash
95
+ # CSV 批量翻译
96
+ qmt -B input.csv -t English
97
+
98
+ # Excel 批量翻译(所有 sheet)
99
+ qmt -B input.xlsx -t Korean
100
+
101
+ # 指定输出文件
102
+ qmt -B input.csv -O output.csv -t English
103
+
104
+ # 首行也翻译(无表头模式)
105
+ qmt -B input.csv -t English --no-header
106
+
107
+ # 断点恢复(中断后从上次位置继续)
108
+ qmt -B input.csv -t English --resume
109
+ ```
110
+
111
+ 默认行为:
112
+ - 首行视为表头,不翻译(`--no-header` 可改变此行为)
113
+ - 输出文件自动命名为 `原文件名_translated.ext`
114
+ - Excel 文件翻译所有工作表
115
+ - 触发 API 限流时自动指数退避重试(2s -> 4s -> 8s -> 16s -> 32s,最多 5 次)
116
+ - 支持 `--resume` 断点恢复,中断后可继续翻译
117
+
118
+ ## 术语管理
119
+
120
+ 固定术语确保特定词汇翻译一致。保存在项目目录 `.qmt/terms.csv`。
121
+
122
+ ```bash
123
+ # 添加术语
124
+ qmt terms add "React" "React"
125
+ qmt terms add "组件" "コンポーネント"
126
+
127
+ # 查看术语列表
128
+ qmt terms list
129
+
130
+ # 删除术语
131
+ qmt terms remove "React"
132
+
133
+ # 清空所有术语
134
+ qmt terms clear
135
+
136
+ # 从 CSV/TSV 文件批量导入
137
+ qmt terms import terms.csv
138
+
139
+ # 翻译时使用内联术语(不保存)
140
+ qmt "React组件开发" -t Japanese --terms "React:React,组件:コンポーネント"
141
+ ```
142
+
143
+ ## 翻译记忆
144
+
145
+ 提供参考翻译对,帮助模型保持翻译风格一致。保存在 `.qmt/memory.csv`。
146
+
147
+ ```bash
148
+ # 添加翻译记忆
149
+ qmt memory add "你好世界" "Hello World"
150
+
151
+ # 查看记忆列表
152
+ qmt memory list
153
+
154
+ # 删除记忆
155
+ qmt memory remove "你好世界"
156
+
157
+ # 清空所有记忆
158
+ qmt memory clear
159
+
160
+ # 从文件批量导入
161
+ qmt memory import memory.csv
162
+ ```
163
+
164
+ ## 领域提示
165
+
166
+ 领域提示告诉模型翻译的专业领域和风格要求,支持两级存储:
167
+
168
+ - **项目级** — 保存在当前目录 `.qmt/domain.md`,优先级最高
169
+ - **全局级** — 保存在 `~/.qmt/domain.md`,作为默认值
170
+
171
+ ```bash
172
+ # 设置项目级领域
173
+ qmt domain set "technology"
174
+
175
+ # 设置全局级领域
176
+ qmt domain set "medical translation, formal tone" --global
177
+
178
+ # 查看当前配置
179
+ qmt domain show
180
+
181
+ # 清除项目级领域
182
+ qmt domain clear
183
+
184
+ # 清除全局级领域
185
+ qmt domain clear --global
186
+ ```
187
+
188
+ 优先级:命令行 `-d` 参数 > 项目级 > 全局级。
189
+
190
+ 翻译时自动加载已保存的领域提示,无需每次手动指定:
191
+
192
+ ```bash
193
+ # 先设置领域
194
+ qmt domain set "game localization, martial arts world view"
195
+
196
+ # 后续翻译自动生效
197
+ qmt "仙缘副本" -t Korean
198
+ qmt -B game_strings.xlsx -t Korean
199
+ ```
200
+
201
+ ## 交互式模式
202
+
203
+ ```bash
204
+ qmt -i -t English
205
+ ```
206
+
207
+ 交互模式下可用命令:
208
+
209
+ | 命令 | 说明 |
210
+ |------|------|
211
+ | `/help` | 显示帮助 |
212
+ | `/target <lang>` | 切换目标语言 |
213
+ | `/source <lang>` | 切换源语言 |
214
+ | `/model <name>` | 切换模型 |
215
+ | `/stream` | 切换流式输出 |
216
+ | `/domain <text>` | 设置领域提示 |
217
+ | `/domain save [global]` | 保存当前领域到项目/全局 |
218
+ | `/domain clear` | 清除当前领域 |
219
+ | `/terms` | 显示当前术语 |
220
+ | `/memory` | 显示当前记忆 |
221
+ | `/verbose` | 切换详细模式 |
222
+ | `/quit` | 退出 |
223
+
224
+ ## 项目结构
225
+
226
+ ```
227
+ src/qmt/
228
+ cli.py # CLI 入口与命令定义
229
+ client.py # Qwen-MT API 客户端
230
+ batch.py # CSV/Excel 批量翻译
231
+ interactive.py # 交互式 REPL
232
+ models.py # 数据模型
233
+ parsers.py # 输入解析
234
+ formatters.py # 终端输出格式化
235
+ store.py # 本地持久化存储
236
+ constants.py # 常量定义
237
+ exceptions.py # 自定义异常
238
+ ```
239
+
240
+ ## 开发
241
+
242
+ ```bash
243
+ # 安装开发依赖
244
+ pip install -e ".[dev]"
245
+
246
+ # 代码检查
247
+ ruff check src/qmt/
248
+
249
+ # 格式化
250
+ ruff format src/qmt/
251
+
252
+ # 运行测试
253
+ pytest
254
+ ```
255
+
256
+ ## License
257
+
258
+ MIT
@@ -0,0 +1,223 @@
1
+ # QMT - Qwen-MT CLI
2
+
3
+ 基于通义千问机器翻译模型 (Qwen-MT) 的命令行翻译工具。支持单句翻译、交互式 REPL、CSV/Excel 批量翻译,并提供术语表、翻译记忆、领域提示等专业翻译辅助功能。
4
+
5
+ ## 安装
6
+
7
+ 需要 Python >= 3.10。
8
+
9
+ ```bash
10
+ pip install -e .
11
+ ```
12
+
13
+ 安装后即可使用 `qmt` 命令。
14
+
15
+ ## 配置
16
+
17
+ 设置 DashScope API Key([申请地址](https://dashscope.console.aliyun.com/)):
18
+
19
+ ```bash
20
+ export DASHSCOPE_API_KEY="sk-xxxxxxxx"
21
+ ```
22
+
23
+ 也可以通过 `--api-key` 参数逐次传入。
24
+
25
+ ## 快速开始
26
+
27
+ ```bash
28
+ # 翻译文本
29
+ qmt "你好世界" -t English
30
+
31
+ # 指定模型
32
+ qmt "Hello World" -t Chinese -m qwen-mt-plus
33
+
34
+ # 翻译文件
35
+ qmt -f article.txt -t English
36
+
37
+ # 管道输入
38
+ echo "你好" | qmt -t English
39
+
40
+ # 流式输出
41
+ qmt "你好世界" -t English --stream
42
+
43
+ # 交互式模式
44
+ qmt -i -t English
45
+ ```
46
+
47
+ ## 可用模型
48
+
49
+ | 模型 | 特点 | 流式 | 语言数 |
50
+ |------|------|------|--------|
51
+ | `qwen-mt-plus` | 最高翻译质量,适用于专业领域 | - | 92 |
52
+ | `qwen-mt-flash` | 通用首选,效果/速度/成本平衡 (默认) | 支持 | 92 |
53
+ | `qwen-mt-lite` | 最快响应速度,适用于实时场景 | 支持 | 31 |
54
+
55
+ ## 批量翻译
56
+
57
+ 支持 CSV (.csv/.tsv) 和 Excel (.xlsx/.xls) 文件的批量翻译。翻译文件第一列内容,结果追加为新列。
58
+
59
+ ```bash
60
+ # CSV 批量翻译
61
+ qmt -B input.csv -t English
62
+
63
+ # Excel 批量翻译(所有 sheet)
64
+ qmt -B input.xlsx -t Korean
65
+
66
+ # 指定输出文件
67
+ qmt -B input.csv -O output.csv -t English
68
+
69
+ # 首行也翻译(无表头模式)
70
+ qmt -B input.csv -t English --no-header
71
+
72
+ # 断点恢复(中断后从上次位置继续)
73
+ qmt -B input.csv -t English --resume
74
+ ```
75
+
76
+ 默认行为:
77
+ - 首行视为表头,不翻译(`--no-header` 可改变此行为)
78
+ - 输出文件自动命名为 `原文件名_translated.ext`
79
+ - Excel 文件翻译所有工作表
80
+ - 触发 API 限流时自动指数退避重试(2s -> 4s -> 8s -> 16s -> 32s,最多 5 次)
81
+ - 支持 `--resume` 断点恢复,中断后可继续翻译
82
+
83
+ ## 术语管理
84
+
85
+ 固定术语确保特定词汇翻译一致。保存在项目目录 `.qmt/terms.csv`。
86
+
87
+ ```bash
88
+ # 添加术语
89
+ qmt terms add "React" "React"
90
+ qmt terms add "组件" "コンポーネント"
91
+
92
+ # 查看术语列表
93
+ qmt terms list
94
+
95
+ # 删除术语
96
+ qmt terms remove "React"
97
+
98
+ # 清空所有术语
99
+ qmt terms clear
100
+
101
+ # 从 CSV/TSV 文件批量导入
102
+ qmt terms import terms.csv
103
+
104
+ # 翻译时使用内联术语(不保存)
105
+ qmt "React组件开发" -t Japanese --terms "React:React,组件:コンポーネント"
106
+ ```
107
+
108
+ ## 翻译记忆
109
+
110
+ 提供参考翻译对,帮助模型保持翻译风格一致。保存在 `.qmt/memory.csv`。
111
+
112
+ ```bash
113
+ # 添加翻译记忆
114
+ qmt memory add "你好世界" "Hello World"
115
+
116
+ # 查看记忆列表
117
+ qmt memory list
118
+
119
+ # 删除记忆
120
+ qmt memory remove "你好世界"
121
+
122
+ # 清空所有记忆
123
+ qmt memory clear
124
+
125
+ # 从文件批量导入
126
+ qmt memory import memory.csv
127
+ ```
128
+
129
+ ## 领域提示
130
+
131
+ 领域提示告诉模型翻译的专业领域和风格要求,支持两级存储:
132
+
133
+ - **项目级** — 保存在当前目录 `.qmt/domain.md`,优先级最高
134
+ - **全局级** — 保存在 `~/.qmt/domain.md`,作为默认值
135
+
136
+ ```bash
137
+ # 设置项目级领域
138
+ qmt domain set "technology"
139
+
140
+ # 设置全局级领域
141
+ qmt domain set "medical translation, formal tone" --global
142
+
143
+ # 查看当前配置
144
+ qmt domain show
145
+
146
+ # 清除项目级领域
147
+ qmt domain clear
148
+
149
+ # 清除全局级领域
150
+ qmt domain clear --global
151
+ ```
152
+
153
+ 优先级:命令行 `-d` 参数 > 项目级 > 全局级。
154
+
155
+ 翻译时自动加载已保存的领域提示,无需每次手动指定:
156
+
157
+ ```bash
158
+ # 先设置领域
159
+ qmt domain set "game localization, martial arts world view"
160
+
161
+ # 后续翻译自动生效
162
+ qmt "仙缘副本" -t Korean
163
+ qmt -B game_strings.xlsx -t Korean
164
+ ```
165
+
166
+ ## 交互式模式
167
+
168
+ ```bash
169
+ qmt -i -t English
170
+ ```
171
+
172
+ 交互模式下可用命令:
173
+
174
+ | 命令 | 说明 |
175
+ |------|------|
176
+ | `/help` | 显示帮助 |
177
+ | `/target <lang>` | 切换目标语言 |
178
+ | `/source <lang>` | 切换源语言 |
179
+ | `/model <name>` | 切换模型 |
180
+ | `/stream` | 切换流式输出 |
181
+ | `/domain <text>` | 设置领域提示 |
182
+ | `/domain save [global]` | 保存当前领域到项目/全局 |
183
+ | `/domain clear` | 清除当前领域 |
184
+ | `/terms` | 显示当前术语 |
185
+ | `/memory` | 显示当前记忆 |
186
+ | `/verbose` | 切换详细模式 |
187
+ | `/quit` | 退出 |
188
+
189
+ ## 项目结构
190
+
191
+ ```
192
+ src/qmt/
193
+ cli.py # CLI 入口与命令定义
194
+ client.py # Qwen-MT API 客户端
195
+ batch.py # CSV/Excel 批量翻译
196
+ interactive.py # 交互式 REPL
197
+ models.py # 数据模型
198
+ parsers.py # 输入解析
199
+ formatters.py # 终端输出格式化
200
+ store.py # 本地持久化存储
201
+ constants.py # 常量定义
202
+ exceptions.py # 自定义异常
203
+ ```
204
+
205
+ ## 开发
206
+
207
+ ```bash
208
+ # 安装开发依赖
209
+ pip install -e ".[dev]"
210
+
211
+ # 代码检查
212
+ ruff check src/qmt/
213
+
214
+ # 格式化
215
+ ruff format src/qmt/
216
+
217
+ # 运行测试
218
+ pytest
219
+ ```
220
+
221
+ ## License
222
+
223
+ MIT