🐛 fix(vscode): Python 的 from 译成「从」

This commit is contained in:
cruldra committed 2026-09-25 01:51:03 +08:00
1 parent 83bdfbe9c4
commit 5ce016ba86
3 files changed
+15 -4

No files matched your search

@@ -20,7 +20,7 @@ export const pythonZhTranslator: Translator = createZhTemplateTranslator({
tokenRole: pythonTokenRole,
keywords: {
'import': '导入',
'from': '来自',
'from': '从',
'as': '作为',
'def': '函数',
'async': '异步',
@@ -132,7 +132,7 @@ describe('python 中文直译', () => {
expect(texts(map)).toEqual({
1: 'Scan a workspace for .env files.',
3: '导入 os',
4: '来自 pathlib 导入 Path 作为 P',
4: '从 pathlib 导入 Path 作为 P',
6: 'MAX_DEPTH = 8',
7: 'skipped = 空列表',
10: '函数 find_env_files(root: 字符串) -> 列表[字符串]',
@@ -152,7 +152,7 @@ describe('python 中文直译', () => {
24: '使用 open(os.path.join(root, found[0])) 作为 handle',
25: 'handle.read()',
26: '捕获 OSError 作为 err',
27: '抛出 RuntimeError(str(err)) 来自 err',
27: '抛出 RuntimeError(str(err)) 从 err',
28: '最终',
29: 'skipped.clear()',
30: '返回 found',
@@ -176,4 +176,15 @@ describe('python 中文直译', () => {
expect(map[1]).toBe('函数 pick(items: 字典[字符串, 整数], list: 集合) -> 元组')
expect(map[2]).toBe('返回 [str(k) 遍历 k 取自 items 如果 k 不在 list]')
})
it('from 在句首译成「从」,yield from 同一个词', async () => {
const source = [
'from typing import Annotated',
'def walk(nodes):',
' yield from nodes',
].join('\n')
const map = texts(await translateAll(py, 'python', pythonZhTranslator, source))
expect(map[1]).toBe('从 typing 导入 Annotated')
expect(map[3]).toBe('产出 从 nodes')
})
})