♻️ refactor(vscode): 代码阅读的翻译插件只经契约拿语言插件的词性和推导式结构

This commit is contained in:
cruldra committed 2026-09-26 16:24:36 +08:00
1 parent 07eaf96a6b
commit 202fa954ba
12 files changed
+185 -76

No files matched your search

+11 -3
View File
@@ -1,7 +1,17 @@
import type { Node, Translator } from '../contract'
import { insideAnnotation, pythonIteration, pythonTokenRole } from '../languages/python'
import { createZhTemplateTranslator } from './zhTemplate'
/** 写在类型注解里(参数、返回值、带注解赋值的 type 节点之内):内置类型名只在这里翻成中文。 */
function insideAnnotation(leaf: Node): boolean {
for (let node = leaf.parent; node; node = node.parent) {
if (node.type === 'type')
return true
if (node.type === 'block' || node.type === 'module')
return false
}
return false
}
function stringContent(node: Node): string {
if (node.type === 'string_content')
return node.text
@@ -17,7 +27,6 @@ export const pythonZhTranslator: Translator = createZhTemplateTranslator({
id: 'python.zh-template',
label: '中文直译',
languageIds: ['python'],
tokenRole: pythonTokenRole,
keywords: {
'import': '导入',
'from': { zh: '从', byContext: { raise_statement: '源自', yield: '自' } },
@@ -87,5 +96,4 @@ export const pythonZhTranslator: Translator = createZhTemplateTranslator({
nodeTemplates: {
conditional_expression: ['如果', { namedChild: 1 }, '则', { namedChild: 0 }, '否则', { namedChild: 2 }],
},
iteration: pythonIteration,
})