✨ feat(vscode): 代码阅读中文直译里 Python 的 not x、TypeScript 的 !x 读成「x 不成立」(如果 root_dir.is_dir() 不成立),Python 走节点模板,TypeScript 用节点读法只换 !,去掉「非」的译法和它补空格的特例

This commit is contained in:
cruldra committed 2026-10-14 15:16:37 +11:00
1 parent e3c8c1b118
commit e1a5f4f012
9 files changed
+99 -35

No files matched your search

@@ -38,7 +38,7 @@ export interface ZhTable {
/** 内置类型:只在 isTypePosition 成立的叶子上按原文查。 */
builtinTypes: Record<string, string>
isTypePosition: (leaf: Node) => boolean
/** 翻成文字的运算符:只认父节点在 operatorParents 里的运算符节点(TS 的非空断言 `x!` 不算)。 */
/** 翻成文字的运算符:只认父节点在 `operatorParents` 里的运算符节点,同一个符号写在别处的照抄。 */
operators: Record<string, string>
operatorParents: string[]
/** 空字面量(没有具名子节点)整个换成一个词:空数组 / 空列表 / 空字典 / 空对象。 */
@@ -60,7 +60,7 @@ export interface ZhTable {
*/
nodeTemplates: Record<string, TemplatePart[]>
/**
* 节点读法:节点类型 → 怎么读成一行译文,给模板排不了的写法(shell 的 `${x:-d}`、`[ -f x ]`、`case`)。
* 节点读法:节点类型 → 怎么读成一行译文,给模板排不了的写法(shell 的 `${x:-d}`、`[ -f x ]`、`case`,TypeScript 一元运算里只有 `!x` 换语序)。
* 命中的节点只输出读法给的,不再照常翻它的子节点;读法返回 undefined 就照常翻。读法里要翻子节点用 ReaderContext.say。
*/
readers?: Record<string, NodeReader>
@@ -903,8 +903,7 @@ function joinTokens(tokens: Token[]): Inline[] {
segments.push(token.group)
else
pushSegment(segments, token.text, token.role, token.offset)
// 「非」是个词,后面补一个空格,不和操作数粘在一起
gap = token.translated && token.raw === '!'
gap = false
})
return segments
}